rm(list=ls())

HomeFile = getwd()

knitr::opts_chunk$set(
  # fig.path='M:/CCIEA.Council.Report/Figures/', # Nicks's
  fig.path = paste0(HomeFile,'/Figures/'),
  cache.path = 'cache/graphics-', 
  echo=FALSE,
  include = TRUE,
  dev='png',
  dpi=300,
  warning=FALSE
  )
# UPDATE FOR CURRENT YEAR  ####
report.year="2020"   # That is, the year it is turned in.  So 2020 for a Feb 2020 report.
main.folder = HomeFile
data.loc = paste(main.folder,"/Time.series/",sep="")
fig.loc = paste(main.folder,"/Figures/",sep="")
cap.loc = paste(main.folder,"/Captions/",sep="")
AltTxt = paste(main.folder,"/AltText/",sep="")
coda = " Lines, colors, and symbols are as in Fig.1."
library(rtf) # to output captions


#####################################################
# load time series plotting code #
# source(paste0(main.folder,"/load.data.r")) # MISSING
main.folder_0 <- main.folder
main.folder <- file.path(main.folder_0, "../R")
source(paste0(main.folder,'/PlotTimeSeries.R'))  
source(paste0(main.folder,'/PlotDomoicAcid.R'))  
source(paste0(main.folder,"/Quadplot_means.r",sep=""))
source(paste0(main.folder,'/NormalizeTimeSeries.r'))
source(paste0(main.folder,"/GetAreaWtdMeans.R" ))
source(paste0(main.folder,"/QuadPlot.R" ))
main.folder <- main.folder_0

bg.polys = FALSE
note.update.status = FALSE # plots "old data" on plot if it hasn't been updated from previous year

### update date from website DO NOT USE ####
# websitedownload ='no'  # yes or no
# source('_UpdateIEADataFromWebsite.R')

Notes on Interpreting Time Series Figures

graphics.off()
jpeg(paste(fig.loc,"example-fig.jpg",sep=""), units='in', res=300, width=6, height=5)

nf <- layout(matrix(c(1,3,
                      2,3),
                      2,2,byrow = TRUE), c(2,2), c(1,1), TRUE)

layout.show(nf)
X = 1:30
# Y = Y2 = c(1.951787,1.631605,3.457652,1.503185,4.863015,6.274109,-1.016788,1.526880,3.908137,4.353510,3.631307,4.362584,3.683589,4.665410,2.294414,1.254683,2.647636,2.933235, 4.818184,6.043274,2.533987,1.564976,7.850845,9.314683,7.865794,10.216519,7.164671,11.329814,9.385541,10.176562)

Y = Y2 = c(1.951787,1.631605,3.457652,NA,NA,NA,-1.016788,1.526880,3.908137,4.353510,3.631307,4.362584,3.683589,4.665410,2.294414,1.254683,2.647636,2.933235, 4.818184,6.043274,2.533987,1.564976,7.850845,9.314683,7.865794,10.216519,7.164671,11.329814,9.385541,10.176562)


SElo = Y-2
SEup = Y+2
X = (1985+X)

XY = data.frame(cbind(X,Y,Y2,SEup,SElo))
colnames(XY) = cbind('year','index','Y2',"SEup","SElo")
XY$timeseries="(a) Trend and recent mean"
XY$metric = NA
XY$type = "current.data"

PlotTimeSeries(XY, Y2 = NA, LWD = 0.8, Pt.cex = 0.5)
#legend("topleft","(a)", inset=-0.11, bty='n')

# Y =  Y2 = c(0.8288388,0.3560032,4.3554672,0.3492971,-1.6653125,3.0814942,7.0659828,0.4611352,2.0977700,1.4968837,5.9732167,5.3339023,6.2231723,2.9405107,6.8632977,8.5882587,2.7173843,5.4305515,5.6159417,3.8396360,5.6711355,4.3574772,5.5107925,5.5223462,7.3474867,8.0262139,6.1562065,4.4223551,3.6068412,2.3166955)

Y =  Y2 = c(0.8288388,0.3560032,4.3554672,0.3492971,0.5,1.06,2.2,0.4611352,2.0977700,1.4968837,5.9732167,5.3339023,6.2231723,2.9405107,6.8632977,8.5882587,2.7173843,NA,NA,3.8396360,NA,4.3574772,5.5107925,5.5223462,7.3474867,8.0262139,6.1562065,2.4223551,1.6068412,1.3166955)


se = rnorm(length(X),0,2)
SElo = Y-2
SEup = Y+2
XY = data.frame(cbind(X,Y,Y2,SEup,SElo))
colnames(XY) = cbind('year','index','Y2',"SEup","SElo")
XY$timeseries="(b) Threshold"
XY$metric = NA
XY$type = "current.data"

PlotTimeSeries(XY, YLIM = c(0,NA), LWD = 0.8, Pt.cex = 0.7, threshold = 3, threshold.correct = TRUE, threshold.loc = 'below')
#legend("topleft","(b)", inset=-0.11, bty='n')
# reset
SElo = NA
SEup = NA
Y2 = NA
Ylab = NA

x = c(1.3,1.1,0.5, -1.5,-0.6)
y = c(2.1, -0.9, -1.5, 1.4, 0.5)
COL = c('black','grey','red','blue','green')


xerrors=NA; yerrors=NA
QuadPlot_means(D1 = x, D2 = y, style=1, Title = "(c) Sample quadplot", bg.polys=bg.polys, PlotLegend = NA, Lmar = 4.5)
# legend("topleft","(c)", inset=c(-0.2, -0.2), bty='n')
graphics.off()

CAP = "(a) Sample time-series plot, with indicator data relative to the mean (black dotted horizontal line) and 1.0 s.d. (solid blue lines) of the full time series. Dotted black line indicates missing data, and points (when included) indicate data. Arrow at the right indicates if the trend over the evaluation period (shaded blue) was positive, negative or neutral. Symbol at the lower right indicates if the recent mean was greater than, less than, or within 1.0 s.d. of the long-term mean. When possible, times series indicate observation error (grey envelope), defined for each plot (e.g., s.d, s.e., 95% confidence intervals); (b) Sample time-series plot with the indicator plotted relative to a threshold value (blue line). Dashed lines indicate upper and lower observation error, again defined for each plot. Dotted black line indicates missing data; (c) Sample quadplot. Each point represents one normalized time series. The position of a point indicates if the times series was increasing or decreasing over the evaluation period and whether the mean recent years of the time series (recent trend) was above or below the long-term average (recent mean). Dashed lines represent 1.0 s.d. of the full time series."

rtffile <- RTF(paste(cap.loc,"ExampleFigure.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Climate and Ocean Drivers

Basin-Scale Indicators

Basin-scale Processes, 2014-2016

source('reset.DFs.R')

website.update=FALSE
if(website.update==TRUE){

download.file(url="http://oceanview.pfeg.noaa.gov/erddap/tabledap/cciea_OC_ONI.csvp?time%2CONI",
              destfile=paste0(data.loc,"Climate and Ocean/oc_ONI.",report.year,".csv", sep=''))

download.file(url="http://oceanview.pfeg.noaa.gov/erddap/tabledap/cciea_OC_PDO.csvp?time%2CPDO",
              destfile=paste0(data.loc,"Climate and Ocean/oc_PDO.",report.year,".csv", sep=''))

download.file(url="http://oceanview.pfeg.noaa.gov/erddap/tabledap/cciea_OC_NPGO.csvp?time%2CNPGO",
              destfile=paste0(data.loc,"Climate and Ocean/oc_NPGO.",report.year,".csv", sep=''))

}

DF1 = load.data("Climate and Ocean","oc_ONI")
DF2 = load.data("Climate and Ocean","oc_PDO")
DF3 = load.data("Climate and Ocean","oc_NPGO")

DF1$metric = "ONI"
DF2$metric = "PDO"
DF3$metric = "NPGO"
DF1$timeseries = "Monthly Ocean Nino Index"
DF2$timeseries = "Monthly Pacific Decadal Oscillation Index"
DF3$timeseries = "Monthly North Pacific Gyre Oscillation Index"
DFL = list(DF1, DF2, DF3)

source('minyr.maxyr.xlim.R')
XLIM = c(as.character(1950), (substring(as.character(Sys.Date()),1,4)))
XLIM = c(XLIM[1],as.character(as.numeric(XLIM[2])+1))

par(mfrow=c(3,1))

for(i in 1:length(DFL)){
  df = DFL[[i]]
  BMAR = c(0.5, 0.5, 0)
  PlotTimeSeries(df, Y2=NA, XLIM = XLIM, LWD = 0.8,  PERIOD=60, TicsEvery = 20, MinorTics = 2,  Bmar = BMAR[i], AltTxt = AltTxt)
}

CAP = paste("Monthly values of the Ocean Nino Index (ONI), Pacific Decadal Oscillation (PDO), and the North Pacific Gyre Oscillation (NPGO) from ",XLIM[1],"-",maxyr,").",coda, sep="")

rtffile <- RTF(paste(cap.loc,"basin-scale-climate.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Regional Climate Indicators

Regional-Scale Processes, 2012-2016

Hypoxia and Ocean Acidification

source('reset.DFs.R')

DF1 = load.data("Climate and Ocean", "oc_do_NH05")
DF2 = load.data("Climate and Ocean", "oc_do_NH25")

# for later....
doNH05 = DF1
doNH25 = DF2

source('minyr.maxyr.xlim.R')

th = 1.4
YLIM = c(0,8)
YL = c(0, 4.0, 8.0)
YMINOR = c(2,6)
te=5

par(mfrow=c(2,1), mar=c(0,0,0,0))
# XLIM = c(1998,2018)
PlotTimeSeries(DF1,  XLIM=XLIM, YLIM=YLIM, TicsEvery=te,  Y.lab.drop = TRUE,  threshold=th, Title = "Dissolved oxygen at 50 m: NH05", AltTxt = AltTxt, AltTxt.file.name = "Dissolved oxygen at 50m NH05")

PlotTimeSeries(DF2, XLIM=XLIM, YLIM=YLIM, TicsEvery=te, Y.lab.drop = TRUE, threshold=th, Title = "Dissolved oxygen at 150 m: NH25", AltTxt = AltTxt, AltTxt.file.name = "Dissolved oxygen at 150m NH25")

CAP = paste("Dissolved oxygen at 50-m and 150-m depths off Oregon through ", maxyr, ". Stations NH05 and NH25 are 5 and 25 km from shore, respectively. The blue line is the hypoxic threshold of ", th," ml dissolved oxygen per liter. Dotted red line indicates missing data.",coda, sep="")

rtffile <- RTF(paste(cap.loc,"DO.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Aragonite

# fig.width = 3.2, fig.height=3
source('reset.DFs.R')
DF1 = load.data("Climate and Ocean", "oc_arg_NH05")
DF2 = load.data("Climate and Ocean", "oc_arg_NH25")

# DFx = load.data("Climate and Ocean", "IEA_Aragonite Saturation_NH5_40m_NH25_150m")
# DFx$index = as.numeric(DFx$index)
# DF1 = DFx[DFx$timeseries == 'Aragonite Saturation' & DFx$Station == 'NH05',]
# DF2 = DFx[DFx$timeseries == 'Aragonite Saturation' & DFx$Station == 'NH25',]

source('minyr.maxyr.xlim.R')
te = 5
th = 1.0
YLIM = c(0,3)
par(mfrow=c(2,1), oma = c(0,0,0,0))

PlotTimeSeries(DF1,  XLIM=XLIM, TicsEvery=te, YLIM=YLIM, Ylab = NA, threshold=th, Title = "Aragonite - 50 m: NH05", AltTxt = AltTxt, AltTxt.file.name = "Aragonite saturation state at 50m NH05")

PlotTimeSeries(DF2,  XLIM=XLIM, TicsEvery=te, threshold=th, YLIM=YLIM, LWD = 1, Ylab = NA, Title = "Aragonite - 150 m: NH25", AltTxt = AltTxt, AltTxt.file.name = "Aragonite saturation state at 150m NH05")

mtext(side=2, "Saturation state", outer = TRUE, line=-1)

CAP = paste("Monthly aragonite saturation values off Newport, Oregon, ", minyr,"-",maxyr,". The blue line indicates aragonite saturation state = 1.0.",coda, sep="")

library(rtf)
rtffile <- RTF(paste(cap.loc,"aragonite.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Domoic acid - HABS

# note the plot function does the aggregation for monthly max
source('reset.DFs.R')
# NOTE - timeseries = Waterbody3
DF = load.data("Domoic Acid", "DomoicAcid_All")
DF$year = as.POSIXct(DF$year)
DF1 = DF[DF$species %in% c('Razor clam','Dungeness crab'),]
DF1$species = as.character(DF1$species)
source('minyr.maxyr.xlim.R')

par(mfrow = c(2,2), mar = c(2,2,2,1), oma=c(0,2,0,0))

regions = c("WA Coast", "OR Coast",  "NCA", "CCA") # for plot order
th=20
XLIM = c(1990,2020)
spp = c('Razor clam', "Dungeness crab")
spp.lc = c('razor clam', "Dungeness crab")
THRESH = c(20,30)
COL = c("darkgrey", "black")


for(i in 1:length(regions)){
  Plot_Domoic_Acid_Monthly(Data.File =  DF1[DF1$Waterbody3 == regions[i],], Xlim = XLIM, Ylab = NA, Ymax = NA, 
                         spp = spp, THRESH = THRESH, COL = COL, Date = 'year', Location = 'Waterbody3', DA='index',                           Species = 'species', legend.inset = c(0.025,-0.1))

}

mtext(side=2, "Monthly max (ppm)", outer= TRUE, line = 1)

CAP = paste0("Monthly maximum domoic acid concentration (ppm) in razor clams and Dungeness clams through ", maxyr, " for WA, OR, northern CA and central CA coast. The ", COL[1], " and ", COL[2], " dashed lines indicate threshold vales of ", THRESH[1], " ppm and ", THRESH[2], " ppm for ", spp.lc[1], " and ", spp.lc[2], ", respectively. Dotted lines indicate missing data.")

rtffile <- RTF(paste(cap.loc,"Domoic_Acid_Monthly_byState_Clams_and_Crabs.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Hydrologic Indicators -- Habitat Indices

snowwater

source('reset.DFs.R')

df0 = load.data('StreamFlow','allTimeSeriesEcoReg')

df = df0[df0$RESPONSE=="Snowpack",]
df$metric = "Apr 1st anom."
df$SEup = df$NINESEVENFIVEquant
df$SElo =df$ZEROTWOFIVEquant
df$mean = df$index
df$index = df$FIVEquant
df$timeseries = df$Ecoregion

x = as.character(df$timeseries)
x = as.factor(x)
levels(x)

DF1 = df[df$timeseries=='Salish Sea & WA Coast',]
DF2 = df[df$timeseries=='Columbia Glaciated',]
DF3 = df[df$timeseries=='Columbia Unglaciated',]
DF4 = df[df$timeseries=='OR & N CA Coast',]
DF5 = df[df$timeseries=='Sacramento - San Joaquin',]
# DF6 = df[df$timeseries=='S CA Bight',]

source('minyr.maxyr.xlim.R')

par(mfcol=c(3,2))

DFL = list(DF1, DF2, DF3, DF4, DF5)
LMAR = c(NA, NA, NA, 5,5)

for(i in 1:length(DFL)){
  df = DFL[[i]]
  PlotTimeSeries(df, XLIM = XLIM, YLIM=c(-3,3), TicsEvery=20, MinorTics=5,
                 Y.axis.labels = c(-3, 0 ,3), yminor = c(-2, -1, 1 , 2), Lmar = LMAR[i], AltTxt = AltTxt)

}

# keep snw.max min they are used in next chunks
snw.maxyr = maxyr
snw.minry = minyr
CAP = paste("Anomalies of April 1st snow-water equivalent (SWE) in five freshwater ecoregions of the CCE through ", snw.maxyr,".",coda," Ecoregions are mapped in Fig. 2.1.", sep="")

rtffile <- RTF(paste(cap.loc,"snowwater.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

stream flow

#par(mfrow = c(1,3))
source('reset.DFs.R')

df0 = data.frame(read.table(paste(data.loc,"StreamFlow/allPlotinfo.2019.csv", sep=""), header=TRUE, sep=","))

no.esus = nrow(df0)

df0$Ecoregion = as.character(df0$Ecoregion)
df0$Ecoregion[df0$Ecoregion=="Sacramento - San Joaquin\n& S CA Bight"]<- "Sacr-S.Jaoquin & SCA Bight"
df0$significantL = as.character(df0$significantL)
df0$significantL[df0$significantL=="gray50"]<-"gray30"
df0$significantR = as.character(df0$significantR)
df0$significantR[df0$significantR=="gray50"]<-"gray30"

### temp
df = df0[df0$RESPONSE=="AugMeanMax",]
x = as.character(df$Ecoregion)
bg.color=c('blue','green','white','yellow','orange','red')
ol.color=c('black','black','black','black','red')
Symbol=c(rep(21,5,NA))

name.order = c('Salish Sea & WA Coast',
          'Columbia Glaciated',
          'Columbia Unglaciated',
          'OR & N CA Coast',
          'Sacr-S.Jauquin & SCA Bight')
xx = data.frame(name.order)
xx$order = 1:length(name.order)
df$order = xx$order[match(df$Ecoregion,xx$name.order)]
df = df[order(df$order),]

QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  Label = df$Ecoregion,
  plot.type = 2,
  flip.colors = TRUE,
  bg.polys = bg.polys,
  style=1,
  PointCex=1.5,
  # PS=14,
  # rng=1.75,
  Title = "August temperature",
  # TitleCex=1.1,
  # TextCex = 0.8,
  bg.color=bg.color,
  ol.color = ol.color,
  # LegendCex = 0.7,
  LegendPointCex = 1.5,
  Symbol=21,
  Rmar =8.25,
  Tmar = 1.1
  )

PERIOD = 5
CAP = paste("Recent (",PERIOD,"-year) trend and average of mean maximum August temperature in  ",no.esus," freshwater ecoregions of the CCE through ",snw.maxyr,". Symbols of ESUs are color-coded from north (blue) to south (orange).  Error bars represent the 2.5% and 97.5% upper and lower credible intervals. Grey error bars overlap zero.  Heavy black error bars differed from zero. ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"stream.temp.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
par(mfrow = c(1,3))
source('reset.DFs.R')

df0 = data.frame(read.table(paste(data.loc,"StreamFlow/allPlotInfoESU.2019.csv", sep=""), header=TRUE, sep=","))
df0$significantL = as.character(df0$significantL)
df0$significantL[df0$significantL=="gray50"]<-"gray50"
df0$significantR = as.character(df0$significantR)
df0$significantR[df0$significantR=="gray50"]<-"gray50"

Names= data.frame(matrix(c(
"U Columbia Sp (CG)", "CKUCS",
"Puget Sound (SS)", "CKPUG",
"WA Coast (SS)", "CKWAC",
"U Columbia Su F (CG)","CKUCF",
"Snake R F (CU)","CKSRF",
"L Columbia R (CU)", "CKLCR",
#"Deschutes R Su F (CU)", 'XXXXXXX',
"M Columbia Sp (CG, CU)","CKMCS",
"Snake R Sp Su (CU)", "CKSRS",
"U Williamette R (CU)" ,"CKUWR",
"OR Coast (ONCC)","CKORC",
"S OR N CA Coast (ONCC)","CKSNC",
"U Klamath Trinity R (ONCC)", "CKUKT",
"CA Coast (ONCC)", "CKCAC",
"Sacramento W (SSJ)","CKSAC",
"C Valley Sp (SSJ)", "CKCVS",
"C Valley F LF (SSJ)", "CKCVF"
), byrow = TRUE, ncol=2))
colnames(Names) = c('esu', 'ESU')
Names$order = 1:nrow(Names)

df0$names = Names$esu[match(df0$ESU, Names$ESU)]
df0$order = Names$order[match(df0$ESU, Names$ESU)]
bg.color = colorRampPalette(c("blue", "green","white","yellow","red"))( 16 )
ol.color="black"
Symbol = c(21,22,23,24,25)
### one day max 
df = df0[df0$RESPONSE=="1daymax",]
df = df[order(df$order), ]
no.esus= nrow(df)

QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  plot.type = 2,
  rng = 1.3,
  flip.colors = TRUE,
  bg.polys = bg.polys,
  Title="1-day max flow",
  # TitleCex = 2,
  TextCex = 0.7,
  # XYLabCex=2,
  # AxisCex = 1.5,
  PointCex = 1.5,
  #Ylab="Long-term status",
  Symbol=Symbol,
  bg.color=bg.color,
  ol.color=ol.color,
  # LegendCex = 0.9,
  LegendPointCex = 1.5,
  PlotLegend = NA
)


######## seven day minimum 

df = df0[df0$RESPONSE=="7daymin",]
df = df[order(df$order), ]
#no.esus= nrow(df)

QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  #Label = df$Ecoregion,
  plot.type = 2,
  bg.polys = bg.polys,
  rng = 1.3,
  Title="7-day min flow",
  # TitleCex = 2,
  PointCex = 1.5,
  TextCex = 0.7,
  # XYLabCex=2,
  # AxisCex = 1.5,
  # Ylab="Long-term status",
  Symbol=Symbol,
  bg.color=bg.color,
  ol.color=ol.color,
  # LegendCex = 0.9,
  LegendPointCex = 1.5,
  PlotLegend = FALSE
)

plot(1:16,1:16, xaxt='n',yaxt='n', pch='', bty="n", xlab=NA, ylab=NA)
legend('topleft',legend=df$names, pt.bg = bg.color, col=ol.color, pch = Symbol, bty = 'n', cex=0.7, pt.cex=1.0, inset=c(-0.3,-0.1))


PERIOD = 5
CAP = paste("Recent (",PERIOD,"-year) trend and average of anomalies in maximum and minimum flow in ",no.esus," freshwater Chinook salmon ESUs in the CCE through ",snw.maxyr,". Symbols of ESUs are color-coded from north (blue) to south (orange).  Error bars represent the 2.5% and 97.5% upper and lower credible intervals. Grey error bars overlap zero.  Heavy black error bars differed from zero. Note that for the 1-day max flow, the Klamath errors did not overlap zero for the short-term trend but are difficult to see because they are very small. ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"flow.esu.doc",sep = ""))  # this can be an .rtf or a .doc
 addParagraph(rtffile, CAP)
 done(rtffile)
par(mfrow = c(1,3))
# one day
source('reset.DFs.R')

df0 = data.frame(read.table(paste(data.loc,"StreamFlow/allPlotInfo.2019.csv", sep=""), header=TRUE, sep=","))
no.esus = nrow(df0)
df = df0[df0$RESPONSE=="1daymax",]

bg.color=c('blue','green','white','yellow','orange','red')
ol.color=c('black')
Symbol=21

## sort plot order 
name.order = c('Salish Sea & WA Coast',
          'Columbia Glaciated',
          'Columbia Unglaciated',
          'OR & N CA Coast',
          'Sacramento - San Joaquin',
          'S CA Bight'
          )

xx = data.frame(name.order)
xx$order = 1:length(name.order)
df$order = xx$order[match(df$Ecoregion,xx$name.order)]
df = df[order(df$order),]
x = as.character(df$Ecoregion)

QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  Label = df$Ecoregion,
  plot.type = 2,
  bg.polys = bg.polys,
  style=1,
  flip.colors=TRUE,
  PointCex=1.5,
  # PS=14,
  rng=1.3,
  Title = "One day max flow",
  # TitleCex=1.25,
  TextCex = 0.7,
  bg.color=bg.color,
  ol.color = ol.color,
  Symbol=21,
  PlotLegend = NA)


### quad seven day
source('reset.DFs.R')

df = df0[df0$RESPONSE=="7daymin",]
xx = data.frame(name.order)
xx$order = 1:length(name.order)
df$order = xx$order[match(df$Ecoregion,xx$name.order)]
df = df[order(df$order),]
x = as.character(df$Ecoregion)
#screen(2)
QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  Label = df$Ecoregion,
  style=1,
  plot.type = 2,
  bg.polys = bg.polys,
  rng=1.3,
  PointCex=1.5,
  Title = "Seven day min flow",
  bg.color=bg.color,
  ol.color = ol.color,
  Symbol=21,
  # TitleCex=1.25,
  # PS=14,
  TextCex = 0.7,
  PlotLegend = NA
)

plot(df$Year3_0.5quant,df$periodx_0.5quant, xaxt='n',yaxt='n', pch='', bty="n", xlab=NA, ylab=NA)
legend('topleft',legend=df$Ecoregion, pt.bg = bg.color, col=ol.color, pch = Symbol, bty = 'n', cex=0.8, pt.cex=1.2)

PERIOD = 5
CAP = paste("Recent (",PERIOD,"-year) trend and average of anomalies in maximum and minimum flow in ",no.esus," freshwater ecoregions of the CCE through ",snw.maxyr,". Symbols of ecoregions are color-coded from north (blue) to south (orange).  Error bars represent the 2.5% and 97.5% upper and lower credible intervals. Grey error bars overlap zero.  Heavy black error bars differed from zero. ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"flow.ecoregion.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
par(mfrow=c(2,2))
source('reset.DFs.R')

df0 = data.frame(read.table(paste(data.loc,"StreamFlow/allPlotInfo.2019.csv", sep=""), header=TRUE, sep=","))
no.esus = nrow(df0)
df0$Ecoregion = as.character(df0$Ecoregion)
df0$Ecoregion[df0$Ecoregion=="Sacramento - San Joaquin\n& S CA Bight"]<- "Sacr-S.Jaoquin & SCA Bight"
df0$Ecoregion[df0$Ecoregion=="S CA Bight"]<- "SCA Bight"
df0$Ecoregion[df0$Ecoregion=="OR & N CA Coast"]<- "OR & NCA Coast"
df0$significantL = as.character(df0$significantL)
df0$significantL[df0$significantL=="gray50"]<-"gray30"
df0$significantR = as.character(df0$significantR)
df0$significantR[df0$significantR=="gray50"]<-"gray30"

### temp
df = df0[df0$RESPONSE=="AugMeanMax",]
name.order = c('Salish Sea & WA Coast',
          'Columbia Glaciated',
          'Columbia Unglaciated',
          'OR & N CA Coast',
          'Sacr-S.Jauquin & SCA Bight')
xx = data.frame(name.order)
xx$order = 1:length(name.order)
df$order = xx$order[match(df$Ecoregion,xx$name.order)]
df = df[order(df$order),]


x = as.character(df$Ecoregion)
bg.color=c('blue','green','white','yellow','orange','red')
ol.color=c('black','black','black','black','red')
Symbol=c(rep(21,5,NA))

QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  Label = df$Ecoregion,
  plot.type = 2,
  flip.colors = TRUE,
  bg.polys = bg.polys,
  style=1,
  PointCex=1.5,
  rng=1.75,
  Title = "Mean max August temp",
  # TitleCex=1.1,
  TextCex = 0.8,
  bg.color=bg.color,
  ol.color = ol.color,
  PlotLegend = NA,
  Symbol=21
  )

### one day max 
df = df0[df0$RESPONSE=="1daymax",]
name.order = c('Salish Sea & WA Coast',
          'Columbia Glaciated',
          'Columbia Unglaciated',
          'OR & N CA Coast',
          'Sacr-S.Jauquin & SCA Bight')
xx = data.frame(name.order)
xx$order = 1:length(name.order)
df$order = xx$order[match(df$Ecoregion,xx$name.order)]
df = df[order(df$order),]
x = as.character(df$Ecoregion)
bg.color=c('blue','green','white','yellow','orange','red')
ol.color=c('black')
Symbol=21

QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  Label = df$Ecoregion,
  plot.type = 2,
  style=1,
  flip.colors=TRUE,
  bg.polys = bg.polys,
  PointCex=1.5,
  rng=1.1,
  Title = "One day max flow",
  # TitleCex=1.25,
  TextCex = 0.8,
  bg.color=bg.color,
  ol.color = ol.color,
  Symbol=21,
  PlotLegend = NA)

df = df0[df0$RESPONSE=="7daymin",]
name.order = c('Salish Sea & WA Coast',
          'Columbia Glaciated',
          'Columbia Unglaciated',
          'OR & N CA Coast',
          'Sacr-S.Jauquin & SCA Bight')
xx = data.frame(name.order)
xx$order = 1:length(name.order)
df$order = xx$order[match(df$Ecoregion,xx$name.order)]
df = df[order(df$order),]
x = as.character(df$Ecoregion)

QuadPlot_means(
  D1 = df$Year3_0.5quant,
  D2 = df$periodx_0.5quant,
  SE.d1.lo = df$Year3_0.025quant,
  SE.d1.up = df$Year3_0.975quant,
  SE.d2.lo = df$periodx_0.025quant,
  SE.d2.up = df$periodx_0.975quant,
  d1.col = df$significantR,
  d2.col = df$significantL,
  Label = df$Ecoregion,
  style=1,
  plot.type = 2,
  bg.polys = bg.polys,
  rng=1.1,
  PointCex=1.5,
  Title = "Seven day min flow",
  bg.color=bg.color,
  ol.color = ol.color,
  Symbol=21,
  # TitleCex=1.25,
  TextCex = 0.8,
  PlotLegend = NA
)
##### legend

plot(1:7,1:7, xaxt='n',yaxt='n', pch='', bty="n", xlab=NA, ylab=NA)
Names = name.order
legend('left',legend=Names, 
       pt.bg = c('blue','green','white','yellow','orange','orange','red'), 
       col=c(rep("black",5),'red','black'), 
       pch = Symbol, bty = 'n', cex=1, pt.cex=1.5, inset= 0)

PERIOD = 5
CAP = paste("Recent (",PERIOD,"-year) trend and average of anomalies of mean maximum August temperature,1-day maximum flow, and 7-day minimum flow in ",no.esus," freshwater ecoregions of the CCE through ",snw.maxyr,". Symbols of ESUs are color-coded from north (blue) to south (orange).  Error bars represent the 2.5% and 97.5% upper and lower credible intervals. Grey error bars overlap zero.  Heavy black error bars differed from zero. Note that for the 1-day max flow, the OR Coast errors did not overlap zero for the short-term trend but are difficult to see because they are very small. ",coda,sep="")
rtffile <- RTF(paste(cap.loc,"swe.1d.7d.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Focal Components of Ecological Integrity

Northern Copepod Biomass Anomaly

source('reset.DFs.R')

copepods = load.data("/Ecological Integrity","IEA_NoSoCopeAnom")

DF1 = copepods[, c('year','month','NorthernBiomassAnomaly','type'),]
colnames(DF1) = c('year','month','index','type')
DF1$timeseries = "Northen copepods"
DF1$metric = "Biomass anomaly"

DF2 = copepods[, c('year','month','SouthernBiomassAnomaly','type'),]
colnames(DF2) = c('year','month','index','type')
DF2$timeseries = "Southern copepods"
DF2$metric = "Biomass anomaly"

source('minyr.maxyr.xlim.R')

par(mfrow=c(2,1), oma = c(0,0,0,0))

PlotTimeSeries(DF1,Y2 = NA, Y.lab.drop = TRUE, Title =  "Northern copepods", Ylab = NA, TicsEvery = 5, Pt.cex = 0.1, PERIOD = 60, AltTxt =  AltTxt) 

PlotTimeSeries(DF2,Y2 = NA, Y.lab.drop = TRUE, Title =   "Southern copepods", Ylab = NA,TicsEvery = 5, Pt.cex = 0.1, PERIOD = 60, AltTxt = AltTxt)
#PlotTimeSeries(DF3,Title =   "Species richness anomaly", TicsEvery = te, PERIOD = 60, AltTxt = AltTxt)
mtext(side=2, "BIomass anomaly", outer=TRUE, line = -1.5)

Ylab=NA
TicsEvery = NA

CAP = paste("Monthly northern and southern copepod biomass anomalies from ",minyr,"-",maxyr,".", coda,sep="")

rtffile <- RTF(paste(cap.loc,"copepods.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

KRILL

source('reset.DFs.R')
DF1 = load.data("Ecological Integrity","THL.EpacificaLengthTable")
source('minyr.maxyr.xlim.R')
DF1$SEup = DF1$index + DF1$SD
DF1$SElo = DF1$index - DF1$SD

PlotTimeSeries(DF1, YLIM = c(0,NA),Ylab = "Length (mm)", TicsEvery = 5, AltTxt = AltTxt, PERIOD=60)

Ylab=NA
TicsEvery = NA

CAP = paste("Mean krill rostral dorsal carapace length (mm) from ",minyr,"-",maxyr,". Grey envelope indicates +/- 1.0 s.d.", coda,sep="")

rtffile <- RTF(paste(cap.loc,"KrillLength.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Regional Forage Availability

source('reset.DFs.R')

DF1 = load.data("Forage",'NCC.ForageJellies')

plot.order = c('',
         'Juvenile chum',
         'Yearling Chinook',
         'Subyearling Chinook',
         'Yearling Coho',
         'Yearling sockeye',
         'YOY rockfish',
         'YOY sablefish',
         'Jack mackerel',
         'Market squid',
         'Aequorea',
         'Chrysaora')

source('minyr.maxyr.xlim.R')

bg.color= c( rep('black',5), rep('white',3) , rep('grey',3) )
ol.color= 'black'
Symbol = c(21,22,23,24,25,23,22,25,21,22,23)


source('minyr.maxyr.xlim.R')

PERIOD = 5
QuadPlot(dframe=DF1,
  PERIOD=PERIOD,
  style=1,
  plot.type=1,
  bg.polys = bg.polys,
  Title = "Northern California Current",
  # TitleCex = 1.5,
  Symbol=Symbol,
  bg.color=bg.color,
  ol.color=ol.color,
  LegendCex = 0.8,
  # LegendPointCex = 1.5,
  Label=plot.order
 )

CAP = paste("Recent (",PERIOD,"-year) trend and average of key forage species in the northern California Current Ecosystem through ",maxyr,". ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"forageN.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source('reset.DFs.R')

DF1 = load.data("Forage",'CCC.Forage')


source('minyr.maxyr.xlim.R')


plot.order = c("Adult sardine",
               "Adult anchovy",
               "YOY sardine",
               "YOY anchovy",
               "YOY Pacific hake",
               "YOY rockfish",
               "YOY sanddabs",
               "Myctophids",
               "Market squid",
               "Krill",
               "Aurelia",
               "Chrysaora", 
               "Pyrosomes")


bg.color = c('black','black',NA,NA,NA,NA,NA,'black',rep('grey',5))
ol.color = "black"
Symbol=c(21,24,21,24,22,23,25,21,21,25,24,23,22)

PERIOD =5
QuadPlot(dframe=DF1,
  Name=DF1$timeseries,
  PERIOD=PERIOD,
  style=1,
  plot.type=1,
  bg.polys = bg.polys,
  Title = "Central California Current",
  # TitleCex = 1.5,
  Symbol=Symbol,
  bg.color=bg.color,
  ol.color=ol.color,
  LegendCex = 0.8,
  # LegendPointCex = 1.5,
  Label=plot.order
 )



CAP = paste("Recent (",PERIOD,"-year) trend and average of key forage species in the central California Current Ecosystem through ",maxyr,". ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"forageC.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source('reset.DFs.R')

df = load.data("Forage",'SCC.forage')


DF1 = df[df$timeseries=="Sardinops.sagax", ] 
DF2 = df[df$timeseries=="Engraulis.mordax", ] 
DF3 = df[df$timeseries=="Merluccius.productus", ] 
DF4 = df[df$timeseries=="Sebastes.spp", ]
DF5 = df[df$timeseries=="Trachurus.symmetricus", ] 
DF6 = df[df$timeseries=="Citharichthys1", ] 
DF7 = df[df$timeseries=="Doryteuthis.opalescens", ]
DF8 = df[df$timeseries=="Southern.mesopelagics", ]

DF1$timeseries = 'Sardine'
DF2$timeseries = 'Anchovy'
DF3$timeseries = 'Hake'
DF4$timeseries = 'Rockfishes'
DF5$timeseries = 'Jack mackerel'
DF6$timeseries = 'Sanddab'
DF7$timeseries = 'Market squid'
DF8$timeseries = 'Southern mesopelagics'

plot.order= c('Sardine',
         'Anchovy',
         'Hake',
         'Rockfishes',
         'Jack mackerel',
         'Sanddab',
         'Southern mesopelagics',
         'Market squid')

DF = rbind(DF1[,c('year','index','type','timeseries','metric')],
           DF2[,c('year','index','type','timeseries','metric')],
           DF3[,c('year','index','type','timeseries','metric')],
           DF4[,c('year','index','type','timeseries','metric')],
           DF5[,c('year','index','type','timeseries','metric')],
           DF6[,c('year','index','type','timeseries','metric')],
           DF7[,c('year','index','type','timeseries','metric')],
           DF8[,c('year','index','type','timeseries','metric')])
DF$timeseries = as.factor(as.character(DF$timeseries))


bg.color=c('black','black',NA,NA,NA,NA,'grey','grey')
ol.color="black"
Symbol=c(21,24,21,22,25,24,21,24)

PERIOD=5

QuadPlot(dframe=DF,
  PERIOD=PERIOD,
  style=1,
  plot.type=1,
  bg.polys = bg.polys,
  Title = "Southern California Current",
  # TitleCex = 1.5,
  Symbol=Symbol,
  bg.color=bg.color,
  ol.color=ol.color,
  LegendCex = 0.8,
  # LegendPointCex = 1.5,
  Label=plot.order,
  Rmar = 6.9,
  Tmar = 1.2
 )


source('minyr.maxyr.xlim.R')

CAP = paste("Recent (",PERIOD,"-year) trend and average of the larvae of key forage species in the southern California Current Ecosystem through ",maxyr,". ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"forageS.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Highly Migratroy species (HMS)

# 9 , 3
par(mfrow = c(1,3))
# spawning potential ####
source('reset.DFs.R')

df = load.data("HMS", "HMS_IEA_Indices")
DFb = df[df$data.type=='spawning biomass',]

x = aggregate(year ~ timeseries, data=DFb, FUN=max)

name.order = c('Bluefin tuna',
         'Yellowfin tuna',
         'Albacore',
         'Bigeye tuna',
         'Skipjack tuna',
         'Blue marlin',
         'Western central Pacific swordfish',
         'Eastern Pacific swordfish')

bg.color=c('blue','yellow','red','green','black',NA,NA,NA,NA)
ol.color=c('black','black','black','black','black','blue','red','blue','blue')
Symbol=c(22, 24,23,25,22,1,2,6,7)

#DFb$timeseries = as.factor(as.character(DFb$timeseries))
PERIOD = 5

 QuadPlot(dframe=DFb,
   PERIOD=PERIOD,
   style=1,
   plot.type=1,
   Title = "Biomass",
   Symbol=Symbol,
   bg.polys = bg.polys,
   bg.color=bg.color,
   ol.color=ol.color,
   Label=name.order,
   PlotLegend = FALSE,
   # PointCex=3,
   # PS=14,
   # TitleCex=1.25,
   TextCex = 0.7 ,
   rng = 2.3)

#######

### recruitment ####

DFr = df[df$data.type=='recruitment',]
DFr = DFr[DFr$timeseries != "Eastern Pacific swordfish",]
DFr$timeseries = as.factor(as.character(DFr$timeseries))

name.order = c('Bluefin tuna',
         'Yellowfin tuna',
         'Albacore',
         'Bigeye tuna',
         'Skipjack tuna',
         'Blue marlin',
         'Western central Pacific swordfish')

 QuadPlot(dframe=DFr,
  PERIOD=PERIOD,
  style=1,
  plot.type=1,
  bg.polys=bg.polys,
  Title = "Recruitment",
  Symbol=Symbol,
  bg.color=bg.color,
  ol.color=ol.color,
  Label=name.order,
  PlotLegend = FALSE,
  # PointCex=3,
  # PS=14,
  # TitleCex=1.25,
  TextCex = 0.7,
  rng = 3.4)

Name = c('Bluefin tuna',
         'Yellowfin tuna',
         'Albacore',
         'Bigeye tuna',
         'Skipjack tuna',
         'Blue marlin',
         'W.C. Pacific swordfish',
         'E. Pacific swordfish')

plot(1:10,1:10, xaxt='n',yaxt='n', pch='', bty="n", xlab=NA, ylab=NA)
legend('topleft',legend=Name, pt.bg = bg.color, col=ol.color, pch = Symbol, bty = 'n', cex=0.8, pt.cex=1)

CAP = paste("Recent trend and average of biomass and recruitment for highly migratory species (HMS) in the California current from the 2014-2016 stock assessments. Data are total biomass for swordfish, relative biomass for skipjack, spawning biomass for bluefin, and female spawning biomass for all other species. ",coda,sep="")


rtffile <- RTF(paste(cap.loc,"HMS.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Salmon

# fig.width=6.2, fig.height=4.25
source('reset.DFs.R')

df0 = load.data("Salmon","WAORIDChinookAbund")
DF1 = df0[df0$timeseries=="UpperColumbia Spr",]
DF1$timeseries = "Upper Columbia Spr"
DF2 = df0[df0$timeseries=="Snake Spr-Sum",]
DF3 = df0[df0$timeseries=="Snake Fall",]
DF4 = df0[df0$timeseries=="Willamette Spr",]
DF5 = df0[df0$timeseries=="Lower Columbia R",]
DF5$timeseries = "Lower Columbia"

df = load.data("Salmon","CASalmonEscapement")
DF6 = df[df$timeseries=="Klamath Fall",]
DF7 = df[df$timeseries=="s.OR-n.CA Coast",]
DF8 = df[df$timeseries=="California Coast",]
DF9 = df[df$timeseries=="Central Valley Spr",]
DF10 = df[df$timeseries=="Central Valley Fall",]
DF11 = df[df$timeseries=="Central Valley Win",]
DF12 = df[df$timeseries=="Central Valley Late",]

name.order = c(as.character(DF1$timeseries[1]),
         as.character(DF2$timeseries[1]),
         as.character(DF3$timeseries[1]),
         as.character(DF4$timeseries[1]),
         as.character(DF5$timeseries[1]),
         as.character(DF6$timeseries[1]),
         as.character(DF7$timeseries[1]),
         as.character(DF8$timeseries[1]),
         as.character(DF9$timeseries[1]),
         as.character(DF10$timeseries[1]),
         as.character(DF11$timeseries[1]),
         as.character(DF12$timeseries[1])
         )

DF = rbind(DF1[,c('year','index','type','timeseries','metric')],
            DF2[,c('year','index','type','timeseries','metric')],
            DF3[,c('year','index','type','timeseries','metric')],
            DF4[,c('year','index','type','timeseries','metric')],
            DF5[,c('year','index','type','timeseries','metric')],
            DF6[,c('year','index','type','timeseries','metric')],
            DF7[,c('year','index','type','timeseries','metric')],
            DF8[,c('year','index','type','timeseries','metric')],
            DF9[,c('year','index','type','timeseries','metric')],
            DF10[,c('year','index','type','timeseries','metric')],
            DF11[,c('year','index','type','timeseries','metric')],
            DF12[,c('year','index','type','timeseries','metric')])
#DF$timeseries = as.factor(as.character(DF$timeseries))

bg.color = c(rep('blue',5),rep('yellow',3),rep('red',4))
ol.color=c('black')
Symbol = c(21:25,21,24,25,21,23,24,25)
PERIOD = 10

 QuadPlot(dframe=DF,
  PERIOD=PERIOD,
  style=1,
  plot.type=1,
  bg.polys=bg.polys,
  Title = "Chinook salmon escapement",
  #TitleCex = 1.4,
  Label= name.order,
  bg.color = bg.color,
  # PointCex=1,
  # TextCex=0.8,
  l.color,
  # LegendCex=0.8,
  # LegendPointCex = 1,
  Symbol = Symbol )

 ##########

source('minyr.maxyr.xlim.R')

CAP = paste("Recent (",PERIOD,"-year) trend and average of Chinook salmon escapement through ", maxyr, ". Recent trend indicates the escapement trend from ", maxyr-PERIOD, "-" ,maxyr, ". Recent average is mean natural escapement (includes hatchery strays) from ",maxyr-PERIOD,"-",maxyr,". " ,coda, sep="")

rtffile <- RTF(paste(cap.loc,"salmon-escapement.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source('reset.DFs.R')

df0 = load.data("Salmon","AtSeaJuvSalmonSurvey")
DF1 = df0[,c('year','SubYear_Chin_Mean','SubYear_Chin_SE','type')]
DF2 = df0[,c('year','Year_Chin_Mean','Year_Chin_SE','type')]
DF3 = df0[,c('year','Year_Coho_Mean','Year_Coho_SE','type')]
colnames(DF1) = colnames(DF2) = colnames(DF3) = c('year','index','SE','type')
DF1$timeseries = 'Chinook - subyearling'
DF2$timeseries = 'Chinook - yearling'
DF3$timeseries = 'Coho - yearling'
DF1$metric = DF2$metric = DF3$metric = "CPUE"

source('minyr.maxyr.xlim.R')

YLIM = c(0,0.6)
par(mfrow=c(3,1))

PlotTimeSeries(DF1, XLIM=XLIM, YLIM=YLIM,  AltTxt = AltTxt)
PlotTimeSeries(DF2, XLIM=XLIM, YLIM=YLIM,  AltTxt = AltTxt)
PlotTimeSeries(DF3, XLIM=XLIM, YLIM=YLIM,  AltTxt = AltTxt)

CAP = paste("At sea juvenile salmon catch (Log10(no/km + 1)) from ",minyr," to ",maxyr," for Chinook and coho salmon. ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"salmon.juv.ts.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Marine Mammals

sealions

source('reset.DFs.R')

DF1 = load.data("Marine Mammals","cciea_MM_pup_count_MelinUpdate") # pup.count
DF1$index = DF1$inde/1000
DF1$SEup = DF1$index + DF1$SE/1000
DF1$SElo = DF1$index - DF1$SE/1000
DF2 = load.data("Marine Mammals","cciea_MM_pup_weight index_MelinUpdate")
#DF2$SEup = DF2$index + DF2$SE
#DF2$SElo = DF2$index - DF2$SE
DF3 = load.data("Marine Mammals","cciea_MM_pup_growth_MelinUpdate")
#DF3$SEup = DF3$index + DF3$SE
#DF3$SElo = DF3$index - DF3$SE

source('minyr.maxyr.xlim.R')

par(mfcol=c(2,1))
te = 5
LWD = 2
Pt.cex = 0.8

PlotTimeSeries(DF1, Ylab = "1000's", Title =  "Sea lion pup count", XLIM = XLIM, YLIM = c(0,NA), TicsEvery=te, LWD = 2, Pt.cex = Pt.cex, AltTxt =  AltTxt) 

#PlotTimeSeries(DF2, Ylab =  "Kg", Title = "Pup weight anomaly", XLIM = XLIM,  TicsEvery=te, AltTxt =  AltTxt) 

PlotTimeSeries(DF3, Ylab =  "Kg/day", Title = "Pup growth rate", XLIM = XLIM,  TicsEvery=te, LWD = LWD, Pt.cex = Pt.cex, AltTxt =  AltTxt) 

TicsEvery = NA

CAP = paste("California sea lion pup counts, and estimated mean daily growth rate of female pups between 4-7 months on San Miguel Island for the ", minyr,"-",maxyr," cohorts.",coda, sep="")

rtffile <- RTF(paste(cap.loc,"sealions.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

t### sealion diet

source('reset.DFs.R')

DF1 = load.data("Marine Mammals","cciea_MM_ADF California sea lion_diet_Melin_long") 
source('minyr.maxyr.xlim.R')

names = c("Juvenile rockfishes",
          "Mackerels",
          "Market squid",
          "Northern anchovy", 
          "Pacific hake",
          "Pacific sardine")
par(mfrow=c(3,2))

for(i in 1:length(names)){
  DF = DF1[DF1$timeseries == names[i],]
  RMAR = 0.5 #ifelse(i %in% c(2,3,5,6), 5, 3.5)
  PlotTimeSeries(DF, Rmar = RMAR, XLIM=XLIM, YLIM = c(0,1), YATS = 4, Ylab = "Frequency")
}



CAP = paste("Diets of california sea lion pups on San Miguel Island for ", minyr,"-",maxyr," cohorts.",coda, sep="")

rtffile <- RTF(paste(cap.loc,"SealionDiet.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Seabirds

source("reset.DFs.R") 
seabirdsNCC = load.data("Seabirds","Seabird - No CC at-sea densities")
seabirdsCCC = load.data("Seabirds","Seabird - Ce CC at-sea densities")
seabirdsSCC = load.data("Seabirds","Seabird - So CC at-sea densities")

DF1 = seabirdsNCC[seabirdsNCC$timeseries=='Sooty shearwater  Jun - NCC',]
DF2 = seabirdsNCC[seabirdsNCC$timeseries=='Cassins auklet  Jun - NCC',]
DF3 = seabirdsNCC[seabirdsNCC$timeseries=='Common murre  Jun - NCC',]

DF4 = seabirdsCCC[seabirdsCCC$timeseries=='Sooty shearwater  Summer - Ce CC',]
DF5 = seabirdsCCC[seabirdsCCC$timeseries=='Cassins auklet  Summer - Ce CC',]
DF6 = seabirdsCCC[seabirdsCCC$timeseries=='Common murre  Summer - Ce CC',]

DF7 = seabirdsSCC[seabirdsSCC$timeseries=='Sooty shearwater  Spring - So CC',]
DF8 = seabirdsSCC[seabirdsSCC$timeseries=='Cassins auklet  Spring - So CC',]
DF9 = seabirdsSCC[seabirdsSCC$timeseries=='Common murre  Spring - So CC',]

source('minyr.maxyr.xlim.R')
#XLIM = c(as.character(1985), as.character(XLIM2))
te = 10
# XLIM = c(NA, 2022)
par(mfrow=c(3,3), oma=c(0,1,0,0))
Xaxis.cex = 0.8
Arrow.cex = 1.5

PlotTimeSeries(DF1, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Sooty shearwater NCC", TicsEvery=te, AltTxt =  AltTxt) 
PlotTimeSeries(DF2, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Cassin's auklet NCC", TicsEvery=te, AltTxt =  AltTxt)
PlotTimeSeries(DF3, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Common murre NCC", TicsEvery=te, AltTxt =  AltTxt)

PlotTimeSeries(DF4, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Sooty shearwater CCC", TicsEvery=te, AltTxt =  AltTxt) 
PlotTimeSeries(DF5, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Cassin's auklet CCC", TicsEvery=te, AltTxt =  AltTxt)
PlotTimeSeries(DF6, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Common murre CCC", TicsEvery=te, AltTxt =  AltTxt)

PlotTimeSeries(DF7, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Sooty shearwater SCC", TicsEvery=te, AltTxt =  AltTxt) 
PlotTimeSeries(DF8, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Cassin's auklet SCC", TicsEvery=te, AltTxt =  AltTxt)
PlotTimeSeries(DF9, Ylab=NA, XLIM = XLIM,  Xaxis.cex = Xaxis.cex, Arrow.cex = Arrow.cex, Title = "Common murre SCC", TicsEvery=te, AltTxt =  AltTxt)


mtext("Density anomaly", side=2, outer=TRUE)

CAP = paste("Anomalies in the summer at-sea densities of sooty shearwaters, Cassin's auklets and common mures in the north, central, and southern California current through ",maxyr,". Data are shipboard counts, transformed as ln(bird density/km2 +1) and expressed as an anomaly relative to the long-term mean. Seabird abundance data from the Northern CCE were collected and provided by Dr. Jeannette Zamon (NOAA). Seabird abundance data from the Central and Southern CCE are collected on SWFSC Rockfish Recruitment and Ecosystem Assessment and CalCOFI surveys, respectively, and are provided by Dr. Bill Sydeman. ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"seabirds.densisty.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source('reset.DFs.R')

seabirdsNCC = load.data("Seabirds","Seabird - No CC at-sea densities")
seabirdsCCC = load.data("Seabirds","Seabird - Ce CC at-sea densities")
seabirdsSCC = load.data("Seabirds","Seabird - So CC at-sea densities")

seabirdsNCC$timeseries = as.character(seabirdsNCC$timeseries)
seabirdsCCC$timeseries = as.character(seabirdsCCC$timeseries)
seabirdsSCC$timeseries = as.character(seabirdsSCC$timeseries)

DF1 = seabirdsNCC[seabirdsNCC$timeseries=='Sooty shearwater  Jun - NCC',]
DF2 = seabirdsNCC[seabirdsNCC$timeseries=='Cassins auklet  Jun - NCC',]
DF3 = seabirdsNCC[seabirdsNCC$timeseries=='Common murre  Jun - NCC',]

DF4 = seabirdsCCC[seabirdsCCC$timeseries=='Sooty shearwater  Summer - Ce CC',]
DF5 = seabirdsCCC[seabirdsCCC$timeseries=='Cassins auklet  Summer - Ce CC',]
DF6 = seabirdsCCC[seabirdsCCC$timeseries=='Common murre  Summer - Ce CC',]

DF7 = seabirdsSCC[seabirdsSCC$timeseries=='Sooty shearwater  Spring - So CC',]
DF8 = seabirdsSCC[seabirdsSCC$timeseries=='Cassins auklet  Spring - So CC',]
DF9 = seabirdsSCC[seabirdsSCC$timeseries=='Common murre  Spring - So CC',]

# change names

DF1$timeseries[DF1$timeseries=='Sooty shearwater  Jun - NCC'] = 'Shearwaters NCC'
DF2$timeseries[DF2$timeseries=='Cassins auklet  Jun - NCC'] ="Auklets NCC"
DF3$timeseries[DF3$timeseries=='Common murre  Jun - NCC'] = "Murre NCC"

DF4$timeseries[DF4$timeseries=='Sooty shearwater  Summer - Ce CC'] = "Shearwaters CCC"
DF5$timeseries[DF5$timeseries=='Cassins auklet  Summer - Ce CC'] = "Auklets CCC"
DF6$timeseries[DF6$timeseries=='Common murre  Summer - Ce CC'] = "Murre CCC"

DF7$timeseries[DF7$timeseries=='Sooty shearwater  Spring - So CC'] = "Shearwaters SCC"
DF8$timeseries[DF8$timeseries=='Cassins auklet  Spring - So CC'] = "Auklets SCC"
DF9$timeseries[DF9$timeseries=='Common murre  Spring - So CC'] = "Murre SCC"

DF = rbind(DF1[,c('year','index','type','timeseries','metric')],
            DF2[,c('year','index','type','timeseries','metric')],
            DF3[,c('year','index','type','timeseries','metric')],
            DF4[,c('year','index','type','timeseries','metric')],
            DF5[,c('year','index','type','timeseries','metric')],
            DF6[,c('year','index','type','timeseries','metric')],
            DF7[,c('year','index','type','timeseries','metric')],
            DF8[,c('year','index','type','timeseries','metric')],
            DF9[,c('year','index','type','timeseries','metric')])

# DF$timeseries = as.factor(as.character(DF$timeseries))

source('minyr.maxyr.xlim.R')

bg.color= c(rep('blue',3),rep('yellow',3),rep('red',3))
# ol.color= c()
Symbol = c(22,24,21)
name.order = c(
         "Shearwaters NCC",
         "Auklets NCC",
         "Murre NCC",
         "Shearwaters CCC",
         "Auklets CCC",
         "Murre CCC",
         "Shearwaters SCC",
         "Auklets SCC",
         "Murre SCC"#,
         )

PERIOD=5
 QuadPlot(dframe=DF,
  PERIOD=PERIOD,
  style=1,
  plot.type=1,
  bg.polys = bg.polys,
  Title = "At-sea seabird densites",
  # TitleCex = 1.4,
  Label = name.order,
  Symbol = Symbol,
  bg.color=bg.color)


CAP = paste("Recent (",PERIOD,"-year) trend and average of seabird at-sea densities during the spring in the California Current in three regions through ",maxyr,". ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"seabirdsQuad.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

HUMAN ACTIVITIES

Coastwide Landings by Major Fisheries

source('reset.DFs.R')

df = load.data("Human Activities","species_landings")
df = df[grep("Landings", df$metric),]
df$metric = "mt x 1000"


DF1 = df[df$timeseries=="Groundfish, no hake coastwide",]# GFlandings
DF2 = df[df$timeseries=="Pacific hake coastwide",]  # hake
DF3 = df[df$timeseries=="Coastal pelagic spp, no squid coastwide",]  #coastalpelagics
DF4 = df[df$timeseries=="Market squid coastwide",]  #coastalpelagics # squid
DF5 = df[df$timeseries=="Shrimp coastwide",]  #shrimplandings
DF6 = df[df$timeseries=="Crab coastwide",]  #crablandings
DF7 = df[df$timeseries=="Salmon commercial coastwide",]  #salmonlandings
DF8 = df[df$timeseries=="Salmon recreational coastwide",]  #salmonlandings
DF8$metric = "1000's fish"
DF9 = df[df$timeseries=="Highly migratory species coastwide",]  #hmslandings
DF10 = df[df$timeseries=="Other species coastwide",]  #salmonlandings
DF11 = df[df$timeseries=="Recreational coastwide",]  #reclandings
DF12 =df[df$timeseries=="Total fisheries coastwide",]  #totallandings

source('minyr.maxyr.xlim.R')
par(mfrow=c(6,2))

rm(DFL)
DFL = list(DF1, DF2, DF3, DF4, DF5, DF6, DF7, DF8, DF9,DF10,DF11,DF12)

for(i in 1:length(DFL)){
  if(i %in% seq(2, length(DFL),2)){Lmar = 5}else{Lmar = 3.5}
  PlotTimeSeries(DF1, XLIM = c(1981,NA),YLIM= c(0, NA),Ylab.cex = 0.8, Lmar= Lmar, AltTxt =  AltTxt) 

}

CAP = paste("Annual landings of West Coast commercial (data from PacFIN) and recreational (data from RecFin) fisheries, including total landings across all fisheries from",minyr,"-",maxyr,".",coda, sep="")

rtffile <- RTF(paste(cap.loc,"landings.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Aquaculture and Seafood Demand

source('reset.DFs.R')

df = load.data("Human Activities","nonfisheries")

DF1 = df[df$timeseries=="Shellfish aquaculture",]
DF2 = df[df$timeseries=="Finfish aquaculture",]
YLIM = c(0,14)
source('minyr.maxyr.xlim.R')

par(mfcol=c(2,1))
PlotTimeSeries(DF1, Ylab = "mt x1000", Title = "Shellfish aquaculture",XLIM = XLIM, YLIM = YLIM,AltTxt =  AltTxt) 
PlotTimeSeries(DF2, Ylab = "mt x1000", XLIM = XLIM, YLIM = YLIM, Title = "Finfish aquaculture", AltTxt =  AltTxt)

CAP = paste("Aquaculture production of shellfish (clams, mussels, oysters) and finfish (Atlantic salmon) in CCE waters from ",minyr,"-",maxyr,".",coda, sep="")


rtffile <- RTF(paste(cap.loc,"aquaculture.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

rm(YLIM)
source('reset.DFs.R')

df = load.data("Human Activities","nonfisheries")

DF1 = df[df$timeseries=="Seafood demand (total)",] # seafooddemand
DF2 = df[df$timeseries=="Seafood demand (per capita)",]# seafooddemandPC

source('minyr.maxyr.xlim.R')
te=20

par(mfcol=c(2,1))
PlotTimeSeries(DF1, YLIM = c(0,NA), Ylab =  "mt x 10^6", Title =  "Seafood consumption (total)", TicsEvery = te, AltTxt =  AltTxt) 
PlotTimeSeries(DF2, Y.lab.drop = TRUE, YLIM = c(0,NA),Ylab =  "Per capita use (kg)",Title = "Seafood consumption (per capita)", TicsEvery = te, AltTxt =  AltTxt)

CAP = paste("Total (metric tons) and per capita use (kg) of fisheries products in the U.S., ",minyr,"-",maxyr,".",coda, sep="")

rtffile <- RTF(paste(cap.loc,"seafood.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

NON-FISHING ACTIVITIES

Human Wellbeing

Social Vulnerability

source('reset.DFs.R')

# these are all incorrect.  Currently for coastwise.
df = load.data("Human Activities","nonfisheries")
DF1 = df[df$timeseries=="Commercial shipping activity",]
source('minyr.maxyr.xlim.R')
par(mfcol=c(1,1))

PlotTimeSeries(DF1, XLIM = c(NA, 2020), YLIM =  c(0,NA), TicsEvery=5, Title = "Commercial shipping activity", AltTxt = AltTxt)

Ylab=NA
TicsEvery=NA
CAP = paste("Distance transited by commercial shipping vessels in the CCE from ", minyr, "-", maxyr, ". ",coda, sep='')

rtffile <- RTF(paste(cap.loc,"shipping.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source('reset.DFs.R')

df = load.data("Human Activities","nonfisheries")
DF1 = df[df$timeseries=="Offshore oil and gas activity",]

source('minyr.maxyr.xlim.R')
par(mfcol=c(1,1))

PlotTimeSeries(DF1, Ylab =  "Oil & gas production", Title = "Offshore oil and gas activity", XLIM=XLIM, TicsEvery=10, MinorTics=2, AltTxt =  AltTxt)

Ylab=NA
TicsEvery=NA
CAP = paste("Normalize index of the sum of oil and gas production from offshore wells in CA from ", minyr, "-", maxyr, ". ", coda, sep='')

rtffile <- RTF(paste(cap.loc,"oilgas.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)

Fleet Diversity Indices

CAP =" Trends in average diversification for US West Coast and Alaskan fishing vessels with over $5K in average revenues (top left) and for vessels in the 2016 West Coast Fleet with over $5K in average revenues, broken out by state (top right), by average gross revenue classes (bottom left) and by vessel length classes (bottom right)."

rtffile <- RTF(paste(cap.loc,"VesselDiversification.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

(APPENDIX) {Supplementary materials to the California Current Integrated Ecosystem Assessement (CCIEA) Status Report 20XX}

Appendix A: LIST OF CONTRIBUTORS TO THIS REPORT, BY AFFILIATIONS}

Appendix B: LIST OF FIGURE AND DATA SOURCES FOR THE MAIN REPORT

Appendix C: CHANGES IN THIS YEARS REPORT, IN RESPONSE TO COUNCIL AND ADVISORY BODY COMMENTS

Appendex C: LIST OF CHANGES IN THIS YEARS REPORT

Appendix D: CONCEPTUAL MODELS OF THE CALIFORNIA CURRENT

Appendix E: CLIMATE AND OCEAN INDICATORS

Appendix E.1: BASIN-SCALE CLIMATE/OCEAN INDICATORS AT SEASONAL TIME SCALES

#calulate winter/summer values for climate drivers, aragonite and dissolved O2
nino = load.data("Climate and Ocean","oc_ONI")
pdo = load.data("Climate and Ocean","oc_PDO")
npgo = load.data("Climate and Ocean","oc_NPGO")

# DFx = load.data("Climate and Ocean", "IEA_Aragonite Saturation_NH5_40m_NH25_150m")
# DFx$index = as.numeric(DFx$index)
# doNH05 = DFx[DFx$timeseries == 'Oxygen' & DFx$Station == 'NH05',c('year','index','timeseries','metric','type')]
# doNH25 = DFx[DFx$timeseries == 'Oxygen' & DFx$Station == 'NH25',c('year','index','timeseries','metric','type')]

doNH05 = load.data("Climate and Ocean","oc_do_NH05")
doNH25 = load.data("Climate and Ocean","oc_do_NH25")
do9090 = load.data("Climate and Ocean","oc_do_900.900")
do9090 = do9090[,c('year','index','timeseries','metric','type')]
do9330 = load.data("Climate and Ocean","oc_do_933.300")
do9330 = do9330[,c('year','index','timeseries','metric','type')]

aragNH05 = load.data("Climate and Ocean", "oc_arg_NH05")
aragNH25 = load.data("Climate and Ocean", "oc_arg_NH25")
# aragNH05 = DFx[DFx$timeseries == 'Aragonite Saturation' & DFx$Station == 'NH05',c('year','index','timeseries','metric','type')]
# aragNH25 = DFx[DFx$timeseries == 'Aragonite Saturation' & DFx$Station == 'NH25',c('year','index','timeseries','metric','type')]

# colnames(aragNH05)=colnames(aragNH25)=colnames(doNH05)=colnames(doNH25) = c('year','month','index','timeseries', 'type')
aragNH25$metric = aragNH05$metric = "Omega"
doNH05$metric = doNH25$metric = "ml/L"

Dfiles = c("nino","pdo","npgo", "aragNH25",'aragNH05','doNH05', 'doNH25','do9090','do9330')

for(i in 1:length(Dfiles)){
  #print(Dfiles[i])
  x = get(Dfiles[i])
  x$yr = as.numeric(substring(x$year, 1,4))
  x$month = as.numeric(substring(x$year, 6,7))
  x$season = ifelse(x$month %in% c(1,2,3),"winter",ifelse(x$month %in% c(7,8,9), 'summer','other'))
  x$n = 1
  seas = c('winter','summer')
  for(k in 1:2){
    xx = aggregate(index~yr , data=x[x$season==seas[k],], FUN='mean')
    xx.sd = aggregate(index~yr, data=x[x$season==seas[k],], FUN='sd')
    xx.n = aggregate(n~yr, data=x[x$season==seas[k],], FUN='sum')
    colnames(xx) = c('year','index')
    se = data.frame(cbind(xx.sd$yr, xx.sd$index[match(xx.sd$yr,xx.n$yr)],
                          xx.n$n[match(xx.sd$yr,xx.n$yr)]))
    colnames(se) = c('yr','sd','n')
    se$se = se$sd/sqrt(se$n)
    xx$SEup = xx$index + se$se[match(xx$year, se$yr)]
    xx$SElo = xx$index - se$se[match(xx$year, se$yr)]

    xx$SEup = ifelse(is.na(xx$SEup)==TRUE,xx$index,xx$SEup)
    xx$SElo = ifelse(is.na(xx$SElo)==TRUE,xx$index,xx$SElo)

    xx$type = x$type[1]
    new.name = paste(Dfiles[i],seas[k],sep="_")
    assign(new.name, xx)
  }
}
source("reset.DFs.R")

DF1 = nino_winter
DF2 = nino_summer
source('minyr.maxyr.xlim.R')
# XLIM = c(as.character(1950), substring(as.character(Sys.Date()),1,4))
te = 20
mt = 5
YLIM = c(-2, 3)

par(mfrow=c(2,1), mar=c(0,0,0,0))
PlotTimeSeries(DF1, Ylab= "ONI", YLIM = YLIM, Title = "Winter", XLIM=XLIM,TicsEvery = te, MinorTics = 5, AltTxt = AltTxt)
PlotTimeSeries(DF2, Ylab= "ONI", YLIM = YLIM, Title = "Summer", XLIM=XLIM,TicsEvery = te, MinorTics = 5, AltTxt = AltTxt)
CAP = paste('Winter (top, Jan-Mar) and Summer (bottom, July-Sep) values of the Ocean Nino Index.', coda)

rtffile <- RTF(paste(cap.loc,"nino.season.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = pdo_winter
DF2 = pdo_summer

source('minyr.maxyr.xlim.R')
# XLIM = c(as.character(1950), substring(as.character(Sys.Date()),1,4))
te = 30
mt =5

par(mfrow=c(2,1), mar=c(0,0,0,0))
PlotTimeSeries(DF1, Y.lab.drop = TRUE, Ylab= "PDO", Title = "Winter", XLIM=XLIM,TicsEvery = te, MinorTics=mt, AltTxt = AltTxt)
PlotTimeSeries(DF2, Y.lab.drop = TRUE, Ylab= "PDO", Title = "Summer", XLIM=XLIM,TicsEvery = te,  MinorTics=mt, AltTxt = AltTxt)

seasonal.pdo.maxyr = maxyr
TicsEvery = NA
CAP = paste('Winter (top, Jan-Mar) and Summer (bottom, July-Sep) values of the Pacific Decadal Oscillation Index.', coda)

rtffile <- RTF(paste(cap.loc,"pdo.season.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = npgo_winter
DF2 = npgo_summer
source('minyr.maxyr.xlim.R')
XLIM = c(as.character(1950), as.character(2020))
te = 20
mt = 5
# PlotTimeSeries(X,Y,Y2, SEup, SElo, plotpoints,XLIM, YLIM, Xlab, Ylab, Xangle, TicsEvery, MinorTics, TicsEvery, MinorTics, Title, ALPHA, PERIOD, ComputerType, AltTxt) 
par(mfrow=c(2,1), mar=c(0,0,0,0))

PlotTimeSeries(DF1, Y.lab.drop = TRUE, Ylab= "NPGO", Title = "Winter", XLIM=XLIM,TicsEvery = te, MinorTics=mt, AltTxt = AltTxt)

PlotTimeSeries(DF2, Y.lab.drop = TRUE, Ylab= "NPGO", Title = "Summer", XLIM=XLIM, TicsEvery = te, MinorTics=mt, AltTxt = AltTxt)

CAP = paste('Winter (top, Jan-Mar) and Summer (bottom, July-Sep) values of the North Pacific Gyre Oscillation Index.', coda)

rtffile <- RTF(paste(cap.loc,"npgo.season.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = sti = load.data("Climate and Ocean",'oc_sti_A_error')
DF2 = lusi = load.data("Climate and Ocean",'oc_lusi_A_error')
DF3 = tumi = load.data("Climate and Ocean",'oc_tumi_A_error')
tumi$index = tumi$index/1000
tumi$SEup = tumi$SEup/1000
tumi$SElo = tumi$SElo/1000
# tumi$metric = "TUMI (x10^3 m^3/s/100m coastline)"
tumi$metric = "TUMI"
source('minyr.maxyr.xlim.R')

te = 20
mt = 5
 Arrow.cex = 1.3

sti.x = levels(sti$timeseries)
par(mfcol = c(6,3))
lat = c(48, 45, 42, 39, 36, 33)
for(i in 1:length(levels(sti$timeseries))){
  DF =  sti[sti$lat==lat[i],]
  tx = ifelse(i==1, as.character(DF$metric[1]),NA)
  Ylab = paste(DF$lat[1],"N")
  PlotTimeSeries(DF, Title=tx, Ylab=Ylab, YLIM = c(0,200),  Arrow.cex = Arrow.cex, TicsEvery = te, MinorTics = mt)
}
for(i in 1:length(levels(lusi$timeseries))){
  DF =  lusi[lusi$lat==lat[i],]
  tx = ifelse(i==1, as.character(DF$metric[1]),NA)
  Ylab = paste(DF$lat[1],"N")
  PlotTimeSeries(DF, Title=tx, Ylab=NA, YLIM = c(0,400), Arrow.cex = Arrow.cex, TicsEvery = te, MinorTics = mt)
}
for(i in 1:length(levels(tumi$timeseries))){
  DF =  tumi[tumi$lat==lat[i],]
  tx = ifelse(i==1, as.character(DF$metric[1]),NA)
  Ylab = paste(DF$lat[1],"N")
  PlotTimeSeries(DF, Title=tx, TitleCex = 0.8, Ylab=NA, YLIM = c(0,60), Arrow.cex = Arrow.cex, TicsEvery = te, MinorTics = mt)
}
CAP = paste('NEED CAPTION TEXT from ', minyr, " to ",maxyr,". ", coda, sep="")

rtffile <- RTF(paste(cap.loc,"sti_lusi_tumi_iea_ts.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix E.2: REGIONAL-SCALE CLIMATE/OCEAN INDICATORS AT SPATIAL AND TEMPORAL SCALES

CAP = "Monthly means of daily upwelling index (top) and anomalies (bottom) for Jan 2012–Sep 2016. Shaded areas denote positive (upwelling-favorable) values in upper panel, and positive anomalies (generally greater than normal upwelling) in lower panel. Anomalies are relative to 1967–2015 monthly means. Units are in m3 s-1 per 100 m of coastline. Daily upwelling index data obtained from http://upwell.pfeg.noaa.gov/erddap/."

rtffile <- RTF(paste(cap.loc,"monthlyupwelling.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix E.3: SEASONAL TRENDS IN DISSOLVED OXYGEN AND OCEAN ACIDIFICATION INDICATORS

source("reset.DFs.R")

DF1 = doNH05_winter
DF2 = doNH25_winter
DF3 = do9090_winter
DF4 = do9330_winter

source('minyr.maxyr.xlim.R')
# XLIM = c(as.character(1950), as.character(XLIM2))
te = 20
th=1.4
tcex=1.0
LWD = 0.6
Pt.cex = 0.5
# PlotTimeSeries(X,Y,Y2, SEup, SElo, plotpoints,XLIM, YLIM, Xlab, Ylab, Xangle, TicsEvery, MinorTics, TicsEvery, MinorTics, Title, ALPHA, PERIOD, ComputerType, AltTxt) 
par(mfrow=c(4,1), mar=c(0,0,0,0))
YLIM=c(0,8)

PlotTimeSeries(DF1, Y.lab.drop = TRUE, YLIM=YLIM, Ylab= "ml/L", LWD = LWD, Pt.cex = Pt.cex, threshold=th, Title = "Winter DO at 50 m: NH05", TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

PlotTimeSeries(DF2, Y.lab.drop = TRUE, YLIM=YLIM, Ylab= "ml/L", LWD = LWD, Pt.cex = Pt.cex, threshold=th, Title = "Winter DO at 150 m: NH25", TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

PlotTimeSeries(DF3, Y.lab.drop = TRUE, YLIM=YLIM, Ylab= "ml/L", LWD = LWD, Pt.cex = Pt.cex, threshold=th, Title = "Winter DO at 150 m: CalCOFI 90.90", TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

PlotTimeSeries(DF4, Y.lab.drop = TRUE, YLIM=YLIM, Ylab= "ml/L", LWD = LWD, Pt.cex = Pt.cex, threshold=th, Title = "Winter DO at 150 m: CalCOFI 93.30",  TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

do.winter.maxyr = maxyr
oreg.do.winter.min = min(DF1$year, na.rm = TRUE)
oreg.do.winter.max = max(DF1$year, na.rm = TRUE)
ca.do.winter.min = min(DF2$year, DF3$year, na.rm = TRUE)
ca.do.winter.max = max(DF2$year, DF3$year, na.rm = TRUE)
#TicsEvery = NA

CAP = paste('Winter (top, Jan-Mar) dissolved oxygen (DO) at 150 m depth off of Oregon, ', oreg.do.winter.min,'-', oreg.do.winter.max,' and southern California, ', ca.do.winter.min, '-',ca.do.winter.max,'. Stations NH25 and 93.30 are < 50 km from the shore; station 90.90 is >300 km from shore. Blue line indicates hypoxic threshold of 1.4 ml O2 per L. ',coda, sep="")

rtffile <- RTF(paste(cap.loc,"DOwinter.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = doNH05_summer
DF2 = doNH25_summer
DF3 = do9090_summer
DF4 = do9330_summer

source('minyr.maxyr.xlim.R')
te=20
th=1.4
par(mfrow=c(4,1), mar=c(0,0,0,0))
tcex=1.0
Pt.cex = 0.5
LWD = 0.6
YLIM=c(0,5)

PlotTimeSeries(DF1, YLIM=YLIM, threshold=th, Ylab= "ml/L", Title = "Summer DO at 50 m: NH05", LWD = LWD, Pt.cex = Pt.cex, TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

PlotTimeSeries(DF2, YLIM=YLIM, threshold=th, Ylab= "ml/L", Title = "Summer DO at 150 m: NH25", LWD = LWD, Pt.cex = Pt.cex,  TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

PlotTimeSeries(DF3, YLIM=YLIM, threshold=th, Ylab= "ml/L", Title = "Summer DO at 150 m: CalCOFI 90.90", LWD = LWD, Pt.cex = Pt.cex, TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

PlotTimeSeries(DF4, YLIM=YLIM, threshold=th, Ylab= "ml/L", Title = "Summer DO at 150 m: CalCOFI 93.30", LWD = LWD, Pt.cex = Pt.cex,  TicsEvery = te, XLIM = XLIM, AltTxt =  AltTxt)

do.summer.maxyr = maxyr
oreg.do.summer.min = min(DF1$year, na.rm = TRUE)
oreg.do.summer.max = max(DF1$year, na.rm = TRUE)
ca.do.summer.min = min(DF2$year, DF3$year, na.rm = TRUE)
ca.do.summer.max = max(DF2$year, DF3$year, na.rm = TRUE)

CAP = paste('Summer (Jul-Sep) dissolved oxygen (DO) at 50-m and 150 m depth off of Oregon, ', oreg.do.winter.min,'-', oreg.do.winter.max,' and southern California, ', ca.do.winter.min, '-',ca.do.winter.max,'. Stations NH05, NH25 and 93.30 are < 50 km from the shore; station 90.90 is >300 km from shore. Blue line indicates hypoxic threshold of 1.4 ml O2 per L. ',coda, sep="")

rtffile <- RTF(paste(cap.loc,"DOsummer.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = aragNH05_winter
DF2 = aragNH25_winter

source('minyr.maxyr.xlim.R')
YLIM = c(0,2)
te=5
th=1
par(mfrow=c(2,1),oma=c(0,0,0,0))
XLIM = c(1998,NA)

PlotTimeSeries(DF1, TicsEvery=te, threshold = th, Title= "Winter - 40m NH05", YLIM=YLIM, XLIM=XLIM, AltTxt = AltTxt)

PlotTimeSeries(DF2,  TicsEvery=te,  threshold = th, Title= "Winter - 150m NH25", YLIM=YLIM, XLIM=XLIM, AltTxt =  AltTxt)

mtext("Aragonite saturation", side=2, outer=TRUE, line=-1.5)

CAP = paste('Winter (Jan-Mar) aragonite saturation values at two stations off of Newport, OR, ', minyr, '-',maxyr,'. The blue line indicates aragonite saturation state = 1.0. Dotted lines indicate +/- 1.0 s.e. ',coda, sep="")

rtffile <- RTF(paste(cap.loc,"arag.winter.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = aragNH05_summer
DF2 = aragNH25_summer

source('minyr.maxyr.xlim.R')
te=5
th=1
XLIM = c(1998,NA)
YLIM=c(0,2)
par(mfrow=c(2,1), oma=c(0,0,0,0))

PlotTimeSeries(DF1, TicsEvery=te, threshold=th, Title = "Summer - 40 m: NH05", XLIM=XLIM, YLIM=YLIM, AltTxt =  AltTxt)
PlotTimeSeries(DF2, TicsEvery=te, threshold = th, Title = "Summer - 150 m: NH25", XLIM=XLIM, YLIM=YLIM,AltTxt =  AltTxt)

mtext("     Aragonite saturation", side=2, outer=TRUE, line=-1.2)
CAP = paste('Summer aragonite saturation values at two stations off of Newport, OR, ',minyr,',',maxyr,'. The blue line indicates aragonite saturation state = 1.0. Dotted lines indicate +/- 1.0 s.e. ', coda, sep = "")

rtffile <- RTF(paste(cap.loc,"arag.summer.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

APENDIX someting -- DOMOIC ACID

source('reset.DFs.R')

DF = load.data("Domoic Acid", "DomoicAcid_All")
DF$year = as.POSIXct(DF$year)

# get just relevant spp
DF1 = DF[DF$species %in% c('Razor clam','Dungeness crab'),]
DF1$species = as.character(DF1$species)
DF1$Waterbody <- as.character(DF1$Waterbody)
DF1$Waterbody[DF1$Waterbody == "Jefferson Coast"] <- "Jefferson County"
DF1$Waterbody[DF1$Waterbody == "Grays Harbor"] <- "Grays Harbor County"
DF1$Waterbody[DF1$Waterbody == "Grays Harbor Coast"] <- "Grays Harbor County"
DF1$Waterbody[DF1$Waterbody == "Willapa Bay"] <- "Pacific County"
DF1$Waterbody[DF1$Waterbody == "Pacific County Coast"] <- "Pacific County"


# note the plot function does the aggregation for monthly max

source('minyr.maxyr.xlim.R')
par(mfrow = c(3,1), mar = c(2,3,2,1), oma = c(0,1,0,0), ps = 10, cex.main = 1.2, cex.lab = 1, cex.axis = 1)



regions = c("Jefferson County", "Grays Harbor County", "Pacific County" )

XLIM = c(1990,2020)
spp = c('Razor clam', "Dungeness crab")

THRESH = c(20,30)
COL = c("grey", "black")
l.inset = c(0,-0.1)

Plot_Domoic_Acid_Monthly(Data.File = subset(DF1, DF1$Waterbody == regions[1]), 
                          Xlim = XLIM, Ylab = NA, Ymax = NA,Title = regions[1], 
                          spp = spp, THRESH = THRESH, COL = COL, Date = 'year', 
                          Location = 'Waterbody', DA='index', Species = 'species', 
                          legend.inset = l.inset)
Plot_Domoic_Acid_Monthly(Data.File = subset(DF1, DF1$Waterbody == regions[2]), 
                          Xlim = XLIM, Ylab = NA, Ymax = 205, Title = regions[2], 
                          spp = spp, THRESH = THRESH, COL = COL, Date = 'year', 
                          Location = 'Waterbody', DA='index', Species = 'species', 
                          legend.inset = l.inset)
Plot_Domoic_Acid_Monthly(Data.File = subset(DF1, DF1$Waterbody == regions[3]), 
                          Xlim = XLIM, Ylab = NA, Ymax = 205,Title = regions[3], 
                          spp = spp, THRESH = THRESH, COL = COL, Date = 'year', 
                          Location = 'Waterbody', DA='index', Species = 'species', 
                          legend.inset = l.inset)



mtext(side=2, "Monthly max (ppm)", outer=TRUE, line=0)

CAP = paste('Monthly maximum values of domoic acid (ppm) off the Washington coast from ',minyr,'-',maxyr,'. Dotted lines indicate threshold values for different species.', sep = "")

rtffile <- RTF(paste(cap.loc,"DomoicAcid.WA.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source('reset.DFs.R')

DF = load.data("Domoic Acid", "DomoicAcid_All")
DF$year = as.POSIXct(DF$year)
DF1 = DF[DF$species %in% c('Razor clam','Dungeness crab'),]
DF1$species = as.character(DF1$species)
# note the plot function does the aggregation for monthly max
source('minyr.maxyr.xlim.R')
par(mfrow = c(4,2), mar = c(4,5,1,2), oma = c(0,0,0,0), ps = 10, cex.main = 1.2, cex.lab = 1, cex.axis = 1)

regions = c("Clatsop", "Tillamook", "Lincoln", "Lane" ,"Douglas","Coos", "Curry" )

for(i in 1:length(regions)){
  DF2 = DF1[DF1$Waterbody == regions[i],]
  Plot_Domoic_Acid_Monthly(Data.File =  DF2, Xlim = c(1990,2020), Ylab = NA, Ymax = NA, 
                           spp = c("Razor clam", "Dungeness crab"),
                           THRESH = c(20, 30), COL = c('grey','black'),
                           Date = 'year', Location = 'Waterbody', DA='index', Species = 'species',
                           legend.inset = c(0,0))

}
mtext(side=2, "Monthly max (ppm)", outer=TRUE, line=-1)

CAP = paste('Monthly maximum values of domoic acid (ppm) off the Oregon coast from ',minyr,'-',maxyr,'. Locations are counties.  Dotted lines indicate threshold values for different species.', sep = "")

rtffile <- RTF(paste(cap.loc,"DomoicAcid.OR.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source('reset.DFs.R')

DF = load.data("Domoic Acid", "DomoicAcid_All")
DF$Date = as.POSIXct(DF$yr.mo)
DF$pecies = as.character(DF$species)
# note the plot function does the aggregation for monthly max
DF1 = DF
source('minyr.maxyr.xlim.R')
par(mfrow = c(3,1), mar = c(4,5,1,2), oma = c(0,0,0,0), ps = 10, cex.main = 1.2, cex.lab = 1, cex.axis = 1)
l.inset = c(0,-0.2)

Plot_Domoic_Acid_Monthly(Data.File =  DF[DF$Waterbody3 == "NCA",], Xlim = c(1990,2020),Ylab = NA, Ymax = NA, 
                          spp = c("Razor clam", "Dungeness crab"),
                          THRESH = c(20, 30), COL = c('grey','black'),
                          Date = 'Date', Location = 'Waterbody3', DA='index', Species = 'species',
                          legend.inset = l.inset)
Plot_Domoic_Acid_Monthly(Data.File =  DF[DF$Waterbody3 == "CCA",], Xlim = c(1990,2020),Ylab = NA, Ymax = NA, 
                          spp = c("Razor clam", "Dungeness crab"),
                          THRESH = c(20, 30), COL = c('grey','black'),
                          Location = 'Waterbody3', DA='index', Species = 'species',
                          legend.inset = l.inset)  

Plot_Domoic_Acid_Monthly(Data.File =  DF[DF$Waterbody3 == "SCA",], Xlim = c(1990,2020),Ylab = NA, Ymax = NA, 
                          spp = c("Rock crab", "Spiny lobster"),
                          THRESH = c(20, 30), COL = c('grey','black'),
                          Location = 'Waterbody3', DA='index', Species = 'species',
                          legend.inset = l.inset)


mtext(side=2, "Monthly max (ppm)", outer=TRUE, line=-1)

CAP = paste('Monthly maximum values of domoic acid (ppm) off the California coast from ',minyr,'-',maxyr,'. Dotted lines indicate threshold values for different species. NCA, CCA, and SCA indicate northern, central and southern California.', sep = "")

rtffile <- RTF(paste(cap.loc,"DomoicAcid.CA.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix F: HABITAT INDICATORS: SNOW-WATER EQUIVALENT AND STREAMFLOW

source("reset.DFs.R")

df0 = load.data('StreamFlow','allTimeSeriesEcoReg')
df = df0[df0$RESPONSE=="AugMeanMax",]
df$metric = "Temp (deg C)"
df$SEup = df$NINESEVENFIVEquant
df$SElo =df$ZEROTWOFIVEquant
df$mean = df$index
df$index = df$FIVEquant
df$timeseries = df$Ecoregion

DF1 = df[df$timeseries=='Salish Sea & WA Coast',]
DF2 = df[df$timeseries=='Columbia Glaciated',]
DF3 = df[df$timeseries=='Columbia Unglaciated',]
DF4 = df[df$timeseries=='OR & N CA Coast',]
DF5 = df[df$timeseries=='Sacramento - San Joaquin\n& S CA Bight',]
DF5$timeseries = 'Sacramento - San Joaquin & S CA Bight'
# DF6 = df[df$Ecoregion=='S CA Bight',]

source('minyr.maxyr.xlim.R')
#XLIM = c(1950, XLIM2)
te = 10
par(mfrow=c(3,2))
YLIM = c(15,25)

PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)
PlotTimeSeries(DF3, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)


#
CAP = paste("Mean maximum stream temperature in August  measured at 466 USGS gauges in six ecoregions from ",minyr,"-",maxyr,".  Gages include both regulated (subject to hydropower operations) and unregulated systems, although trends were similar when these systems were examined separately. ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"stream.temp.ecoregion.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

df0 = load.data('StreamFlow','allTimeSeriesEcoReg')
df = df0[df0$RESPONSE=="1daymax",]
df$metric = "1-day max"
df$SEup = df$NINESEVENFIVEquant
df$SElo =df$ZEROTWOFIVEquant
df$mean = df$index
df$index = df$FIVEquant
df$timeseries = df$Ecoregion

DF1 = df[df$timeseries=='Salish Sea & WA Coast',]
DF2 = df[df$timeseries=='Columbia Glaciated',]
DF3 = df[df$timeseries=='Columbia Unglaciated',]
DF4 = df[df$timeseries=='OR & N CA Coast',]
DF5 = df[df$timeseries=='Sacramento - San Joaquin',]
DF6 = df[df$timeseries=='S CA Bight',]

source('minyr.maxyr.xlim.R')
te = 10
par(mfrow=c(3,2))
YLIM = c(-2,4)
PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)
PlotTimeSeries(DF3, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF6, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)

#
CAP = paste("Anomalies of the 1-day maximum streamflow measured at 213 gauges in six ecoregions for ",minyr,"-",maxyr,".  Gages include both regulated (subject to hydropower operations) and unregulated systems, although trends were similar when these systems were examined separately.",coda)

rtffile <- RTF(paste(cap.loc,"streamflow1.ecoregion.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

df0 = load.data('StreamFlow','allTimeSeriesEcoReg')
df = df0[df0$RESPONSE=="7daymin",]
df$metric = "7-day min"

df$SEup = df$NINESEVENFIVEquant
df$SElo =df$ZEROTWOFIVEquant
df$mean = df$index
df$index = df$FIVEquant
df$timeseries = df$Ecoregion

DF1 = df[df$timeseries=='Salish Sea & WA Coast',]
DF2 = df[df$timeseries=='Columbia Glaciated',]
DF3 = df[df$timeseries=='Columbia Unglaciated',]
DF4 = df[df$timeseries=='OR & N CA Coast',]
DF5 = df[df$timeseries=='Sacramento - San Joaquin',]
DF6 = df[df$timeseries=='S CA Bight',]


DF1 = df[df$timeseries=='Salish Sea & WA Coast',]
DF2 = df[df$timeseries=='Columbia Glaciated',]
DF3 = df[df$timeseries=='Columbia Unglaciated',]
DF4 = df[df$timeseries=='OR & N CA Coast',]
DF5 = df[df$timeseries=='Sacramento - San Joaquin',]
DF6 = df[df$timeseries=='S CA Bight',]


source('minyr.maxyr.xlim.R')
te = 10
par(mfrow=c(3,2))
YLIM=c(-2,4)
PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)
PlotTimeSeries(DF3, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75)
PlotTimeSeries(DF6, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, AltTxt = AltTxt, Lmar = 4.25)

#
CAP = paste("Anomalies of the 7-day minimum streamflow measured at 213 gauges in six ecoregions for ",minyr,"-",maxyr,"  Gages include both regulated (subject to hydropower operations) and unregulated systems, although trends were similar when these systems were examined separately.",coda)

rtffile <- RTF(paste(cap.loc,"streamflow7.ecoregion.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")


df0 = load.data('StreamFlow','allTimeSeriesESU')
df1 = df0[df0$RESPONSE == '1daymax',]
df1$metric = "One-day max"
# no.esus = 16 #length(levels(df1$timeseries))

df1$SEup = df1$X0.975quant
df1$SElo =df1$X0.025quant
df1$mean = df1$index
df1$index = df1$X0.5quant

# fix time series names
esu = data.frame(matrix(
  c("CKCAC", "CA Coast (ONCC)",
  "CKCVF", "C Valley F LF (SSJ)", 
  "CKCVS", "C Valley Sp (SSJ)",
  "CKWAC","WA Coast (SS)",
  "CKLCR", "L Columbia R (CU)",
  "CKMCS", "M Columbia Sp (CG, CU)",
  "CKORC", "OR Coast (ONCC)",
  "CKPUG", "Puget Sound (SS)",
  "CKSAC", "Sacramento W (SSJ)",
  "CKSNC", "S OR N CA Coast (ONCC)",
  "CKSRF", "Snake R F (CU)", 
  "CKSRS", "Snake R Sp Su (CU)", 
  "CKUCF", "U Columbia Su F (CG)",
  "CKUCS", "U Columbia Sp (CG)",
  "CKUKT", "U Klamath Trinity R (ONCC)",
  "CKUWR", "U Williamette R (CU)"), byrow=TRUE, ncol=2))
colnames(esu) = c('region','esu')
no.esus = nrow(esu)

df1$timeseries = esu$esu[match(df1$REGION, esu$region)]

DF1 = df1[df1$timeseries=="U Columbia Sp (CG)",]
DF2 = df1[df1$timeseries=="Puget Sound (SS)",]
DF3 = df1[df1$timeseries=="WA Coast (SS)",]
DF4 = df1[df1$timeseries=="U Columbia Su F (CG)",]
DF5 = df1[df1$timeseries=="Snake R F (CU)",]
DF6 = df1[df1$timeseries=="L Columbia R (CU)",]
DF7 = df1[df1$timeseries=="Deschutes R Su F (CU)",]
DF8 = df1[df1$timeseries=="M Columbia Sp (CG, CU)",]
DF9 = df1[df1$timeseries=="Snake R Sp Su (CU)",]
DF10 = df1[df1$timeseries=="U Williamette R (CU)",]
DF11 = df1[df1$timeseries=="OR Coast (ONCC)",]
DF12 = df1[df1$timeseries=="S OR N CA Coast (ONCC)",]
DF13 = df1[df1$timeseries=="U Klamath Trinity R (ONCC)",]
DF14 = df1[df1$timeseries=="CA Coast (ONCC)",]
DF15 = df1[df1$timeseries=="Sacramento W (SSJ)",]
DF16 = df1[df1$timeseries=="C Valley Sp (SSJ)",]
DF17 = df1[df1$timeseries=="C Valley F LF (SSJ)",]



source('minyr.maxyr.xlim.R')
TicsEvery = 10
Ylab = NA
te = 10
YLIM=c(-2,4)

par(mfrow=c(8,2), oma=c(0,3,0,0))

PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,  Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF3, XLIM = XLIM, TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM,TicsEvery=te,  Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF6, XLIM = XLIM, YLIM=YLIM,TicsEvery=te,  Ylab=NA, AltTxt = AltTxt)
# PlotTimeSeries(DF7, XLIM = XLIM, TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF8, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF9, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF10, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF11, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF12, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF13, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF14, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF15, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF16, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF17, XLIM = XLIM, YLIM=YLIM,TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
mtext(side=2, "One-day maximum flow anomaly", outer=TRUE)

CAP = paste("Anomalies of the 1-day maximum streamflow measured at 213 gauges in",no.esus,"Chinook salmon ESUs for ",minyr,"-",maxyr,".  Gages include both regulated (subject to hydropower operations) and unregulated systems, although trends were similar when these systems were examined separately.",coda)

rtffile <- RTF(paste(cap.loc,"streamflow1.esu.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

df0 = load.data('StreamFlow','allTimeSeriesESU')
df1 = df0[df0$RESPONSE == '7daymin',]
df1$metric = "Seven-day min"
# no.esus = 16 #length(levels(df1$timeseries))

df1$SEup = df1$X0.975quant
df1$SElo =df1$X0.025quant
df1$mean = df1$index
df1$index = df1$X0.5quant

# fix time series names
# fix time series names
esu = data.frame(matrix(
  c("CKCAC", "CA Coast (ONCC)",
  "CKCVF", "C Valley F LF (SSJ)", 
  "CKCVS", "C Valley Sp (SSJ)",
  "CKWAC","WA Coast (SS)",
  "CKLCR", "L Columbia R (CU)",
  "CKMCS", "M Columbia Sp (CG, CU)",
  "CKORC", "OR Coast (ONCC)",
  "CKPUG", "Puget Sound (SS)",
  "CKSAC", "Sacramento W (SSJ)",
  "CKSNC", "S OR N CA Coast (ONCC)",
  "CKSRF", "Snake R F (CU)", 
  "CKSRS", "Snake R Sp Su (CU)", 
  "CKUCF", "U Columbia Su F (CG)",
  "CKUCS", "U Columbia Sp (CG)",
  "CKUKT", "U Klamath Trinity R (ONCC)",
  "CKUWR", "U Williamette R (CU)"), byrow=TRUE, ncol=2))
colnames(esu) = c('region','esu')
no.esus = nrow(esu)

df1$timeseries = esu$esu[match(df1$REGION, esu$region)]

DF1 = df1[df1$timeseries=="U Columbia Sp (CG)",]
DF2 = df1[df1$timeseries=="Puget Sound (SS)",]
DF3 = df1[df1$timeseries=="WA Coast (SS)",]
DF4 = df1[df1$timeseries=="U Columbia Su F (CG)",]
DF5 = df1[df1$timeseries=="Snake R F (CU)",]
DF6 = df1[df1$timeseries=="L Columbia R (CU)",]
# DF7 = df1[df1$timeseries=="Deschutes R Su F (CU)",]
DF8 = df1[df1$timeseries=="M Columbia Sp (CG, CU)",]
DF9 = df1[df1$timeseries=="Snake R Sp Su (CU)",]
DF10 = df1[df1$timeseries=="U Williamette R (CU)",]
DF11 = df1[df1$timeseries=="OR Coast (ONCC)",]
DF12 = df1[df1$timeseries=="S OR N CA Coast (ONCC)",]
DF13 = df1[df1$timeseries=="U Klamath Trinity R (ONCC)",]
DF14 = df1[df1$timeseries=="CA Coast (ONCC)",]
DF15 = df1[df1$timeseries=="Sacramento W (SSJ)",]
DF16 = df1[df1$timeseries=="C Valley Sp (SSJ)",]
DF17 = df1[df1$timeseries=="C Valley F LF (SSJ)",]

source('minyr.maxyr.xlim.R')
TicsEvery = 10

Ylab = NA
te = 10

par(mfrow=c(8,2), oma=c(0,3,0,0))
YLIM = c(-2,4)
PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF3, Y.lab.drop = TRUE, XLIM = XLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF6, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
# PlotTimeSeries(DF7, XLIM = XLIM, TicsEvery=te, Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF8, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF9, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF10, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,  Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF11, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF12, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF13, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF14, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF15, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF16, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
PlotTimeSeries(DF17, XLIM = XLIM, YLIM=YLIM, TicsEvery=te,   Ylab=NA, AltTxt = AltTxt)
mtext(side=2, "Seven-day minimum flow anomaly", outer=TRUE)

CAP = paste("Anomalies of the 7-day minimum streamflow measured at 213 gauges in",no.esus,"Chinook salmon ESUs for ",minyr,"-",maxyr,".  Gages include both regulated (subject to hydropower operations) and unregulated systems, although trends were similar when these systems were examined separately.",coda)

rtffile <- RTF(paste(cap.loc,"streamflow7.esu.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix G REGIONAL FORAGE AVAILABILITY

Appendix G.1 NORTHERN CALIFORNIA CURRENT FORAGE

source("reset.DFs.R")

DF1 = load.data("Forage",'NCC.ForageJellies')

source('minyr.maxyr.xlim.R')

plot.order = c(
         'Juvenile chum',
         'Yearling Chinook',
         'Subyearling Chinook',
         'Yearling Coho',
         'Yearling sockeye',
         'YOY rockfish',
         'YOY sablefish',
         'Jack mackerel',
         'Market squid',
         'Aequorea',
         'Chrysaora')

source('minyr.maxyr.xlim.R')
par(mfrow = c(6,2))
lmar = rep(c(3.5,5),10)
for(i in 1:length(plot.order)){
  DF = DF1[DF1$timeseries==plot.order[i],]
  if(i %in% c(1,3,5,10)){GG = TRUE}else{GG = FALSE}
  PlotTimeSeries(DF, Y.lab.drop = GG, Ylab = "CPUE", XLIM=XLIM, YLIM = c(0,NA), Title=DF$timeseries[1], TicsEvery=5, AltTxt =  AltTxt, Lmar=lmar[i])
}


CAP = paste("Geometric mean CPUEs (Log10(no. km-1+ 1)) of key forage groups in the Northern CCE, from surface trawls conducted as part of the BPA Plume Survey,",minyr, '-' ,maxyr,'. ', coda)

rtffile <- RTF(paste(cap.loc,"Nforage.ts.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix F.2: CENTRAL CALIFORNIA CURRENT FORAGE

source("reset.DFs.R")

df = load.data("Forage",'CCC.Forage')
df$SE[is.na(df$SE)] <- 0
df$SEup = df$index + df$SE
df$SElo = df$index - df$SE
DF1 = df
source('minyr.maxyr.xlim.R')

plot.order = c("Adult sardine",
               "Adult anchovy",
               "YOY sardine",
               "YOY anchovy",
               "YOY Pacific hake",
               "YOY rockfish",
               "YOY sanddabs",
               "Myctophids",
               "Market squid",
               "Krill",
               "Aurelia",
               "Chrysaora", 
               "Pyrosomes")


source('minyr.maxyr.xlim.R')

par(mfrow = c(7,2))
lmar = rep(c(3.5,5),10)
for(i in 1:length(plot.order)){
  DF = DF1[DF1$timeseries==plot.order[i],]
  PlotTimeSeries(DF, Ylab = "CPUE", XLIM=XLIM, YLIM = c(0,NA), Xaxis.cex = 0.8,  Title=DF$timeseries[1], TicsEvery=5, AltTxt =  AltTxt, Lmar=lmar[i])
}


#

CAP = paste("Geometric mean CPUEs (mean (ln catch+1)) of key forage groups in the Central CCE, from the SWFSC Rockfish Recruitment and Ecosystem Assessment during ", minyr, "-", maxyr, ". ", coda,", with the exception that shaded errors in these figures represent standard deviations of log transformed catches.", sep='')

rtffile <- RTF(paste(cap.loc,"Cforage.ts.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix G.3: SOUTHERN CALIFORNIA CURRENT FORAGE

source("reset.DFs.R")

df = load.data("Forage",'SCC.forage')

DF1 = df[df$timeseries=="Sardinops.sagax", ] 
DF2 = df[df$timeseries=="Engraulis.mordax", ] 
DF3 = df[df$timeseries=="Merluccius.productus", ] 
DF4 = df[df$timeseries=="Sebastes.spp", ]
DF5 = df[df$timeseries=="Trachurus.symmetricus", ] 
DF6 = df[df$timeseries=="Citharichthys1", ] 
DF7 = df[df$timeseries=="Southern.mesopelagics", ] 
DF8 = df[df$timeseries=="Doryteuthis.opalescens", ] 


Name = c('Sardine',
         'Anchovy',
         'Hake',
         'Rockfishes',
         'Jack mackerel',
         'Sanddab',
         'Southern mesopelagics',
         'Market squid')

source('minyr.maxyr.xlim.R')
te = 10
par(oma=c(0,1,0,0))
Ylab = "CPUE"

par(mfrow=c(4,2))

PlotTimeSeries(DF1,Ylab = Ylab, XLIM=XLIM, Title = Name[1],   TicsEvery=te, AltTxt =  AltTxt, Rmar = 0.75)
PlotTimeSeries(DF2,Ylab = Ylab, XLIM=XLIM, Title = Name[2],   TicsEvery=te, AltTxt =  AltTxt, Lmar=4.25)
PlotTimeSeries(DF3,Ylab = Ylab, XLIM=XLIM, Title = Name[3],   TicsEvery=te, AltTxt =  AltTxt, Rmar = 0.75)
PlotTimeSeries(DF4,Ylab = Ylab, XLIM=XLIM, Title = Name[4],   TicsEvery=te, AltTxt =  AltTxt, Lmar=4.25)
PlotTimeSeries(DF5,Ylab = Ylab, XLIM=XLIM, Title = Name[5],   TicsEvery=te, AltTxt =  AltTxt, Rmar = 0.75)
PlotTimeSeries(DF6, Y.lab.drop = TRUE,Ylab = Ylab, XLIM=XLIM, Title = Name[6],   TicsEvery=te, AltTxt =  AltTxt, Lmar=4.25)
PlotTimeSeries(DF7,Ylab = Ylab, XLIM=XLIM, Title = Name[7],   TicsEvery=te, AltTxt =  AltTxt, Rmar = 0.75)
PlotTimeSeries(DF7,Ylab = Ylab, XLIM=XLIM, Title = Name[8],   TicsEvery=te, AltTxt =  AltTxt, Lmar = 4.25)
#mtext("log abundance index (ln x+1)", side = 2 , line=-2, outer=TRUE)

CAP = paste("Mean abundance (ln(abundance+1)) of the larvae of key forage species in the southern CCE, from spring CalCOFI surveys during ", minyr, '-', maxyr, ". ", coda, sep="")

rtffile <- RTF(paste(cap.loc,"Sforage.ts.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Highly migratory Species

biomass

par(mfrow = c(4,2))
source("reset.DFs.R")

df = load.data("HMS", "HMS_IEA_Indices")
DFb = df[df$data.type=='spawning biomass',]
DFb$SElo = DFb$index - DFb$SD
DFb$SEup = DFb$index + DFb$SD


### biomass ####
DF1 = DFb[DFb$timeseries=="Bluefin tuna",]
DF1$index = DF1$index/1000
DF1$SEup = DF1$SEup/1000
DF1$SElo= DF1$SElo/1000
DF1$metric = "mt x 1000"

DF2 =  DFb[DFb$timeseries=="Yellowfin tuna",]
DF2$index = DF2$index/100
DF2$SEup = DF2$SEup/100
DF2$SElo= DF2$SElo/100
DF2$metric = "Index x 100"

DF3 = DFb[DFb$timeseries=="Albacore",]
DF3$index = DF3$index/1000
DF3$SEup = DF3$SEup/1000
DF3$SElo= DF3$SElo/1000
DF3$metric = "mt x 1000"

DF4 =  DFb[DFb$timeseries=="Bigeye tuna",]
DF4$index = DF4$index/1000
DF4$SEup = DF4$SEup/1000
DF4$SElo= DF4$SElo/1000
DF4$metric = "mt x 1000"

DF5 =  DFb[DFb$timeseries=="Skipjack tuna",]
DF5$metric = "Rel. biomass"

DF6 = DFb[DFb$timeseries=="Blue marlin",]
DF6$index = DF6$index/1000
DF6$SEup = DF6$SEup/1000
DF6$SElo= DF6$SElo/1000
DF6$metric = "mt x 1000"

DF7 =  DFb[DFb$timeseries=="Eastern Pacific swordfish",]
DF7$index = DF7$index/1000
DF7$SEup = DF7$SEup/1000
DF7$SElo= DF7$SElo/1000
DF7$metric = "mt x 1000"

DF8 =  DFb[DFb$timeseries=="Western central Pacific swordfish",]
DF8$index = DF8$index/1000
DF8$SEup = DF8$SEup/1000
DF8$SElo= DF8$SElo/1000
DF8$metric = "mt x 1000"

source('minyr.maxyr.xlim.R')

YLIM = c(0,NA)

PERIOD = 5

x = paste0("DF",1:8)
k1 = seq(2,8,2)
k2 = seq(1,8,2)
for(i in 1:length(x)){
  XX = get(x[i])
  LMAR = if(i %in% k1){LMAR = 4.25}else{LMAR = 3.5}
  RMAR = if(i %in% k2){RMAR = 0.75}else{RMAR = 0}
  PlotTimeSeries(XX, Y.lab.drop = TRUE, PERIOD = PERIOD,XLIM=XLIM, YLIM = YLIM, 
                 TicsEvery=10, AltTxt = AltTxt, Rmar = RMAR, Lmar = LMAR, Xaxis.cex = 0.8  )

}

CAP = paste("Biomass for highly migratory species (HMS) in the California current to ", maxyr,". ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"HMS.biomass.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

recruitment

source("reset.DFs.R")

par(mfrow=c(3,2))

df = load.data("HMS", "HMS_IEA_Indices")
DFr = df[df$data.type=='recruitment',]
DFr$SElo = DFr$index - DFr$SD
DFr$SEup = DFr$index + DFr$SD

### recruitment ####
DF1 = DFr[DFr$timeseries=="Bluefin tuna",]
DF1$index = DF1$index/1000
DF1$SEup = DF1$SEup/1000
DF1$SElo= DF1$SElo/1000
DF1$metric = "No x 10^6"

DF2 = DFr[DFr$timeseries=="Yellowfin tuna",]
DF2$index = DF2$index/1000
DF2$SEup = DF2$SEup/1000
DF2$SElo= DF2$SElo/1000
DF2$metric = "No x 10^6"

DF3 = DFr[DFr$timeseries=="Albacore",]
DF3$index = DF3$index/1000
DF3$SEup = DF3$SEup/1000
DF3$SElo= DF3$SElo/1000
DF3$metric = "No x 10^6"

DF4 = DFr[DFr$timeseries=="Bigeye tuna",]
DF4$index = DF4$index/1000
DF4$SEup = DF4$SEup/1000
DF4$SElo= DF4$SElo/1000
DF4$metric = "No x 10^6"

DF5 = DFr[DFr$timeseries=="Skipjack tuna",]
DF5$metric = "Index"

DF6 = DFr[DFr$timeseries=="Blue marlin",]
DF6$index = DF6$index/1000
DF6$SEup = DF6$SEup/1000
DF6$SElo= DF6$SElo/1000
DF6$metric = "No x 10^6"

source('minyr.maxyr.xlim.R')
te = 10
PERIOD = 5
Xaxis.cex = 0.8

PlotTimeSeries(DF1, PERIOD=PERIOD, XLIM=XLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF2, PERIOD=PERIOD, XLIM=XLIM, TicsEvery=te, AltTxt = AltTxt, Ylab_line = 3, Lmar=4.255, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF3, PERIOD=PERIOD, XLIM=XLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF4, PERIOD=PERIOD, XLIM=XLIM, TicsEvery=te, AltTxt = AltTxt, Ylab_line = 3,Lmar=4.255, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF5, PERIOD=PERIOD, XLIM=XLIM, TicsEvery=te, AltTxt = AltTxt, Rmar = 0.75, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF6, PERIOD=PERIOD, XLIM=XLIM, TicsEvery=te, AltTxt = AltTxt, Ylab_line = 3,Lmar=4.255, Xaxis.cex =Xaxis.cex)

CAP = paste("Recruitment for highly migratory species (HMS) in the California current through ", maxyr,". ",coda,sep="")

rtffile <- RTF(paste(cap.loc,"HMS.recuitment.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix H: CHINOOK SALMON ESCAPEMENT INDICATORS

Appendix H.1: CALIFORNIA CHINOOK SALMON ESCAPEMENTS

source("reset.DFs.R")

df = load.data("Salmon","CASalmonEscapement")
DF1 = df[df$timeseries=="s.OR-n.CA Coast",]
DF2 = df[df$timeseries=="California Coast",]
DF3 = df[df$timeseries=="Klamath Fall",]
DF4 = df[df$timeseries=="Central Valley Spr",]
DF5 = df[df$timeseries=="Central Valley Fall",]
DF6 = df[df$timeseries=="Central Valley Win",]
DF7 = df[df$timeseries=="Central Valley Late",]

source('minyr.maxyr.xlim.R')
te = 10
PERIOD=10
Ylab = NA
Xaxis.cex = 0.8

YLIM = c(-2,4)
par(mfrow=c(4,2), oma=c(0,3,0,0))
PlotTimeSeries(DF1, Ylab = Ylab,   XLIM=XLIM, YLIM=YLIM, PERIOD=PERIOD, TicsEvery = te, AltTxt =  AltTxt, Rmar = 0.75, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF2, Ylab = Ylab,   XLIM=XLIM, YLIM=YLIM, PERIOD=PERIOD, TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF3, Ylab = Ylab,   XLIM=XLIM, YLIM=YLIM, PERIOD=PERIOD, TicsEvery = te, AltTxt =  AltTxt, Rmar = 0.75, Xaxis.cex =Xaxis.cex)
plot(1:10,1:10, xaxt='n', yaxt="n", bty='n', pch="", ylab=NA)
PlotTimeSeries(DF4, Ylab = Ylab,   XLIM=XLIM, YLIM=YLIM, PERIOD=PERIOD, TicsEvery = te, AltTxt =  AltTxt, Rmar = 0.75, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF5, Ylab = Ylab,   XLIM=XLIM, YLIM=YLIM, PERIOD=PERIOD, TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF6, Ylab = Ylab,   XLIM=XLIM, YLIM=YLIM, PERIOD=PERIOD, TicsEvery = te, AltTxt =  AltTxt, Rmar = 0.75, Xaxis.cex =Xaxis.cex)
PlotTimeSeries(DF7, Ylab = Ylab,   XLIM=XLIM, YLIM=YLIM, PERIOD=PERIOD, TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex)

mtext("Escapement anomaly", side=2, outer=TRUE)
TicsEvery = NA
Ylab = NA

CAP = paste("Anomalies of escapement of wild Chinook salmon in California watersheds through ",  maxyr, ". ", coda, sep='')

rtffile <- RTF(paste(cap.loc,"chinook.ts.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)

Appendix H.2: WASHINGTON/OREGON/IDAHO CHINOOK SALMON ESCAPEMENTS

source("reset.DFs.R")

df0 = load.data("Salmon","WAORIDChinookAbund")
DF1 = df0[df0$timeseries=="Snake Spr-Sum",]
DF2 = df0[df0$timeseries=="Snake Fall",]
DF3 = df0[df0$timeseries=="Willamette Spr",]
DF4 = df0[df0$timeseries=="UpperColumbia Spr",]
DF4$timeseries = "Upper Columbia Spr"
DF5 = df0[df0$timeseries=="Lower Columbia R",]

source('minyr.maxyr.xlim.R')
TicsEvery = 10
PERIOD=10
Ylab = NA
YLIM = c(-2,4)
Xaxis.cex = 0.8
par(mfrow=c(3,2), oma=c(0,3,0,0))
XLIM = c(1969, 2020)

PlotTimeSeries(DF1, Ylab=Ylab,   XLIM=XLIM, YLIM = YLIM, PERIOD=PERIOD,AltTxt = AltTxt, Rmar = 0.75, Xaxis.cex = Xaxis.cex)
PlotTimeSeries(DF2, Ylab=Ylab,   XLIM=XLIM,  YLIM = YLIM, PERIOD=PERIOD,AltTxt = AltTxt, Lmar=4.25, Xaxis.cex = Xaxis.cex)
PlotTimeSeries(DF3, Ylab=Ylab,   XLIM=XLIM,  YLIM = YLIM, PERIOD=PERIOD,AltTxt = AltTxt, Rmar = 0.75, Xaxis.cex = Xaxis.cex)
plot(1:10,1:10, xaxt='n', yaxt="n", bty='n', pch="", ylab=NA)
PlotTimeSeries(DF4, Ylab=Ylab,   XLIM=XLIM,  YLIM = YLIM, PERIOD=PERIOD,AltTxt = AltTxt, Rmar = 0.75, Xaxis.cex = Xaxis.cex)
PlotTimeSeries(DF5, Ylab=Ylab,   XLIM=XLIM,  YLIM = YLIM, PERIOD=PERIOD,AltTxt = AltTxt, Lmar=4.25, Xaxis.cex = Xaxis.cex)
mtext("Escapement anomaly", side=2, outer=TRUE)


CAP = paste("Anomalies of escapement of wild Chinook salmon in Washington, Oregon, and Idaho watersheds through ", maxyr, ". ", coda, sep="")


rtffile <- RTF(paste(cap.loc,"chinook.waor.ts.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)

Appenix I: DEMERSAL COMMUNITY STRUCTURE

source("reset.DFs.R")
df = load.data('Ecological Integrity','Crab.to.Fish.Ratio')

DF1 = df[df$timeseries=='Crab:Finfish ratio - North',]
DF2 = df[df$timeseries=='Crab:Finfish ratio - South',]

source('minyr.maxyr.xlim.R')
te = 5

YLIM = c(0, 0.6)
Ylab = "Biomass ratio"
par(mfrow=c(2,1))
PlotTimeSeries(DF1, Title = "Crab:Fish - north", YLIM=YLIM, Ylab= "Biomass ratio", XLIM=c(2002,XLIM[2]), TicsEvery = te, AltTxt = AltTxt)

PlotTimeSeries(DF2, Title = "Crab:Fish - south", YLIM=YLIM, Ylab = "Biomass ratio", XLIM=c(2002,XLIM[2]), TicsEvery = te, AltTxt = AltTxt)

cranfinfish_ts_min = substring(min(DF1$year, DF2$year,DF3$year,DF4$year, na.rm = TRUE),1,4)
cranfinfish_ts_max = substring(max(DF1$year, DF2$year,DF3$year,DF4$year, na.rm = TRUE),1,4)
CAP = paste("Ratio of crab biomass to finfish biomass for the NMFS West Coast Groundfish Trawl Survey through ", cranfinfish_ts_max, ". ", coda, sep="")

rtffile <- RTF(paste(cap.loc,"crabfinfish.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)

Appendix J: SEABIRDS

At sea densities

source("reset.DFs.R") 
seabirdsNCC = load.data("Seabirds","Seabird - No CC at-sea densities")
seabirdsCCC = load.data("Seabirds","Seabird - Ce CC at-sea densities")
seabirdsSCC = load.data("Seabirds","Seabird - So CC at-sea densities")

DF1 = seabirdsNCC[seabirdsNCC$timeseries=='Sooty shearwater  Jun - NCC',]
DF2 = seabirdsNCC[seabirdsNCC$timeseries=='Cassins auklet  Jun - NCC',]
DF3 = seabirdsNCC[seabirdsNCC$timeseries=='Common murre  Jun - NCC',]

DF4 = seabirdsCCC[seabirdsCCC$timeseries=='Sooty shearwater  Summer - Ce CC',]
DF5 = seabirdsCCC[seabirdsCCC$timeseries=='Cassins auklet  Summer - Ce CC',]
DF6 = seabirdsCCC[seabirdsCCC$timeseries=='Common murre  Summer - Ce CC',]

DF7 = seabirdsSCC[seabirdsSCC$timeseries=='Sooty shearwater  Spring - So CC',]
DF8 = seabirdsSCC[seabirdsSCC$timeseries=='Cassins auklet  Spring - So CC',]
DF9 = seabirdsSCC[seabirdsSCC$timeseries=='Common murre  Spring - So CC',]

source('minyr.maxyr.xlim.R')
#XLIM = c(as.character(1985), as.character(XLIM2))
te = 10
YLIM = c(-2,2)
Xaxis.cex = Xaxis.cex


par(mfrow=c(3,3), oma=c(0,1,0,0))
PlotTimeSeries(DF1, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Sooty shearwater NCC", TicsEvery=te, AltTxt =  AltTxt) 
PlotTimeSeries(DF2, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Cassin's auklet NCC", TicsEvery=te, AltTxt =  AltTxt)
PlotTimeSeries(DF3, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Common murre NCC", TicsEvery=te, AltTxt =  AltTxt)

PlotTimeSeries(DF4, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Sooty shearwater CCC", TicsEvery=te, AltTxt =  AltTxt) 
PlotTimeSeries(DF5, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Cassin's auklet CCC", TicsEvery=te, AltTxt =  AltTxt)
PlotTimeSeries(DF6, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Common murre CCC", TicsEvery=te, AltTxt =  AltTxt)

PlotTimeSeries(DF7, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Sooty shearwater SCC", TicsEvery=te, AltTxt =  AltTxt) 
PlotTimeSeries(DF8, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Cassin's auklet SCC", TicsEvery=te, AltTxt =  AltTxt)
PlotTimeSeries(DF9, Ylab=NA, XLIM = XLIM, YLIM=YLIM,   Title = "Common murre SCC", TicsEvery=te, AltTxt =  AltTxt)


mtext("Density anomaly", side=2, outer=TRUE)

CAP = paste("Anomalies in the summer at-sea densities of sooty shearwaters, Cassin's auklets and common mures in the north, central, and southern California current through ",maxyr,". Data are shipboard counts, transformed as ln(bird density/km2 +1) and expressed as an anomaly relative to the long-term mean. Seabird abundance data from the Northern CCE were collected and provided by Dr. Jeannette Zamon (NOAA). Seabird abundance data from the Central and Southern CCE are collected on SWFSC Rockfish Recruitment and Ecosystem Assessment and CalCOFI surveys, respectively, and are provided by Dr. Bill Sydeman. ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"seabirds.ts.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Diet

source("reset.DFs.R")

diet = load.data("Seabirds","Seabird - Ano Neuvo RHAU diet")
diet$metric = "Proportion"

DF1 = diet[diet$timeseries=="Northern anchovy",]
DF2 = diet[diet$timeseries=="Rockfish juveniles",]
DF3 = diet[diet$timeseries=="Market squid",]
DF4 = diet[diet$timeseries=="Pacific saury",]

source('minyr.maxyr.xlim.R')

par(mfcol=c(2,2), oma=c(0,1,0,0))
YLIM = c(0,1)
PlotTimeSeries(DF1, XLIM = XLIM,  YLIM = YLIM, AltTxt =  AltTxt, Ylab=NA) 
PlotTimeSeries(DF2, XLIM = XLIM,  YLIM = YLIM, AltTxt =  AltTxt, Ylab=NA)
PlotTimeSeries(DF3, XLIM = XLIM,  YLIM = YLIM, AltTxt =  AltTxt, Ylab=NA)
PlotTimeSeries(DF4, XLIM = XLIM,  YLIM = YLIM, AltTxt =  AltTxt, Ylab=NA) 
mtext(side=2, "Proportion of auklet chick diet", outer=TRUE)

seabirds.maxyr = maxyr
CAP = paste("Rhinoceros auklet chick diets at Ano Neuvo through ",seabirds.maxyr,". Data provided by Oikonos/Point Blue (ryan@oikonos.org). ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdDiet.an.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

diet = load.data("Seabirds","Seabird - Destruction Island RHAU diet")
#diet$index = diet$index/100

DF1 = diet[diet$timeseries=="Northern anchovy",]
DF2 = diet[diet$timeseries=="Pacific herring",]
DF3 = diet[diet$timeseries=="Rockfish juveniles",]
DF4 = diet[diet$timeseries=="Smelts",]

source('minyr.maxyr.xlim.R')
XLIM = c(as.character(2007), as.character(yr))
te = 5
par(mfcol=c(2,2), oma=c(0,1,0,0))
YLIM = c(0, 1)
PlotTimeSeries(DF1, XLIM = XLIM,  TicsEvery=te, YLIM = YLIM,  AltTxt =  AltTxt, Ylab=NA) 
PlotTimeSeries(DF2, XLIM = XLIM,  TicsEvery=te, YLIM = YLIM,  AltTxt =  AltTxt, Ylab=NA)
PlotTimeSeries(DF3, XLIM = XLIM,  TicsEvery=te, YLIM = YLIM,  AltTxt =  AltTxt, Ylab=NA)
PlotTimeSeries(DF4, XLIM = XLIM,  TicsEvery=te, YLIM = YLIM,  AltTxt =  AltTxt, Ylab=NA) 
mtext(side=2, "Proportion of auklet chick diet", outer=TRUE)

seabirds.maxyr = maxyr
CAP = paste("Rhinoceros auklet chick diets at Destruction Island through ",seabirds.maxyr,". Rhinoceros auklet chick diets at Destruction Island through 2017. Lines and symbols as in Fig. 1. Data courtesy of the Washington Rhinoceros Auklet Ecology Project (scott.pearson@dfw.wa.gov). ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdDiet.di.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

diet = load.data("Seabirds","Seabird - Yaquina Head diet COMU")
diet$index = diet$index/100

DF1 = diet[diet$timeseries=="Smelts",]
DF2 = diet[diet$timeseries=="Herring and sardines",]
DF3 = diet[diet$timeseries=="Pacific sandlance",]
DF4 = diet[diet$timeseries=="Flatfishes",]
DF5 = diet[diet$timeseries=="Rockfish juveniles",]

source('minyr.maxyr.xlim.R')
te = 5
par(mfcol=c(3,2))
YLIM = c(0,1)
PlotTimeSeries(DF1, XLIM = XLIM,    TicsEvery = te, YLIM = YLIM, AltTxt =  AltTxt, Ylab=NA) 
PlotTimeSeries(DF2, XLIM = XLIM,    TicsEvery = te, YLIM = YLIM,  AltTxt =  AltTxt,Ylab="Proportion of diet")
PlotTimeSeries(DF3, XLIM = XLIM,    TicsEvery = te, YLIM = YLIM,  AltTxt =  AltTxt, Ylab=NA)
PlotTimeSeries(DF4, XLIM = XLIM,    TicsEvery = te, YLIM = YLIM,  AltTxt =  AltTxt, Ylab=NA) 
PlotTimeSeries(DF5, XLIM = XLIM,    TicsEvery = te, YLIM = YLIM,  AltTxt =  AltTxt, Ylab=NA) 

seabirds.maxyr = maxyr
CAP = paste("Common murre chick diets at Yaquina Head through ",seabirds.maxyr,". Data provided by the Yaquina Head Seabird Colony Monitoring Project (rob.suryan@noaa.gov). ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdDiet.yh.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

brac = load.data("Seabirds","Seabird - SE Farallon diet BRAC")
caau = load.data("Seabirds","Seabird - SE Farallon diet CAAU")
comu = load.data("Seabirds","Seabird - SE Farallon diet COMU")
pigu = load.data("Seabirds","Seabird - SE Farallon diet PIGU")
rhau = load.data("Seabirds","Seabird - SE Farallon diet RHAU")

DF1 = data.frame(rbind(brac, caau, rhau, comu, pigu))

DF1$id = paste0(DF1$timeseries,DF1$metric)
# set plot order here
ID = c("Northern anchovy% BRAC diet", 
       "Rockfish juveniles% BRAC diet", 
       "Euphausia pacifica% CAAU diet",
       "Thysanoessa spinifera% CAAU diet",
       "Rockfish juveniles% PIGU diet" ,
       "Northern anchovy% COMU diet",
       "Rockfish juveniles% COMU diet", 
       "Salmon juveniles% COMU diet",
       "Northern anchovy% RHAU diet",     
      "Rockfish juveniles% RHAU diet")   

source('minyr.maxyr.xlim.R')

par(mfcol=c(5,2))
YLIM = c(0,1)

for(i in 1:length(ID)){
  DFx = DF1[DF1$id ==ID[i],]
  if(i %in% 6:10){LMAR = 5}else{LMAR = 3.5}
  PlotTimeSeries(DFx, XLIM = XLIM,  TicsEvery = 10, YLIM = c(0,1), AltTxt =  AltTxt, Lmar = LMAR) 

}


seabirds.maxyr = maxyr
CAP = paste("Farallon bird diet through ",seabirds.maxyr,". BRAC = Brandt' cormorant; CAAU = Casin's auklet; COMU = common murre; PIGU = pigeon guillemot; RHAU = rhinoceros auklet. Data provided by XXXXXXXX. ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdDiet.far.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = load.data("Seabirds","Seabird - SE Farallon productivity")
DF1$timeseries = as.character(DF1$timeseries)
DF1$timeseries[DF1$timeseries == "Brandts cormorant"] <- "Brandt's cormorant"
DF1$timeseries[DF1$timeseries == "Cassins auklet"] <- "Cassin's auklet"
ID = levels(as.factor(DF1$timeseries))


source('minyr.maxyr.xlim.R')

par(mfcol=c(5,1), oma = c(0,2,0,0))
YLIM = c(0,1)

for(i in 1:length(ID)){
  DFx = DF1[DF1$timeseries ==ID[i],]
  PlotTimeSeries(DFx, XLIM = XLIM, TicsEvery = 10, 
                  Xaxis.cex = 0.8, Ylab = NA, AltTxt =  AltTxt) 

}
mtext(side=2, "Productivity anomaly", outer=TRUE, line=0)

seabirdsP.maxyr = maxyr
CAP = paste("Seabird productivity anomaly at the Farallon Islands ",seabirdsP.maxyr,". Data provided by XXXXXXXX. ",coda, sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdProductivity.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = load.data("Seabirds","Seabird - Ano Neuvo RHAU anchovy length")
DF1$metric = "Fork length (mm)"
DF1$SEup = DF1$index + DF1$SD
DF1$SElo = DF1$index - DF1$SD

source('minyr.maxyr.xlim.R')
te = 5

PlotTimeSeries(DF1, XLIM = XLIM, YLIM = c(0,NA), TicsEvery = te, AltTxt =  AltTxt) 

CAP = paste("Size of anchovy brought to rhinoceros auklet chicks at Ano Nuevo from ",minyr, '-',maxyr,". Error envelope shows +/- 1.0 s.d. Data provided by Oikonos/Point Blue (ryan@oikonos.org).",coda, sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdDiet.anchovy.size.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Mortality

source("reset.DFs.R")

df = load.data("Seabirds","Seabird - COASST beached birds")

DF1 = df[df$timeseries=="Cassins auklet (Oct - Feb)",]
DF1$timeseries = "Cassin's auklet (Oct - Feb)"
DF2 = df[df$timeseries=="Common murre (Jun- Dec)",]
DF3 = df[df$timeseries=="Northern fulmar (Oct - Feb)",]
DF4 = df[df$timeseries=="Sooty shearwater (May - Oct)",]


source('minyr.maxyr.xlim.R')

par(mfcol=c(2,2), oma=c(0,1,0,0))
te = 5

YLIM = c(0,NA) # c(0,8)

PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF1$Y2, Y.outlier = DF1$Y.outlier, AltTxt =  AltTxt, Ylab=NA) 

PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF2$Y2, Y.outlier = DF2$Y.outlier, AltTxt =  AltTxt, Ylab=NA) 

PlotTimeSeries(DF3, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF3$Y2, Y.outlier = DF3$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF4$Y2, Y.outlier = DF4$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

mtext(side=2, "Encounter rate (dead birds/km)", cex=1, outer=TRUE)

seabirds.maxyr = maxyr
CAP = paste("Encounter rate of dead birds on west coast beaches through ",seabirds.maxyr,"."," The mean and trend of the last five years is evaluated versus the mean and s.d. of the full time series but with the outliers removed.  Open circles indicate outliers.  The dashed lines indicate upper and lower s.d. of the full time series with outliers removed.  Blue shaded box indicates the evaluation period and the upper an lower s.d. of the full time series with the outliers included. Data provided by the Coastal Observation and Seabird Survey Team (https://depts.washington.edu/coasst/).", sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdMortality.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

NOte to self. The North and Central mortalities are graphed separately here and combined below. They are the same data plotted two ways.

source("reset.DFs.R")

df = load.data("Seabirds","Seabird - BeachCombers beached birds Central")

DF1 = df[df$timeseries=="Brandts Cormorant(Apr - Nov) Central",]
DF1$timeseries = "Brandt's Cormorant (Apr - Nov) Central"

DF2 = df[df$timeseries=="Cassins auklet (Oct - Feb) Central",]
DF2$timeseries = "Cassin's auklet (Oct - Feb) Central"

DF3 = df[df$timeseries=="Common murre (Jun- Dec) Central",]

DF4 = df[df$timeseries=="Northern fulmar (Oct - Feb) Central",]
DF5 = df[df$timeseries=="Sooty shearwater (May - Oct) Central",]


source('minyr.maxyr.xlim.R')

par(mfcol=c(5,1), oma=c(0,1,0,0))
te = 5

YLIM = c(0,NA) # c(0,8)

PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF1$Y2, Y.outlier = DF1$Y.outlier, AltTxt =  AltTxt, Ylab=NA) 

PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF2$Y2, Y.outlier = DF2$Y.outlier, AltTxt =  AltTxt, Ylab=NA) 

PlotTimeSeries(DF3, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF3$Y2, Y.outlier = DF3$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF4$Y2, Y.outlier = DF4$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

PlotTimeSeries(DF5, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF5$Y2, Y.outlier = DF5$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

mtext(side=2, "Encounter rate (dead birds/km)", cex=1, outer=TRUE)

seabirds.maxyr = maxyr
CAP = paste("Encounter rate of dead birds CENTRAL XXXXXXXX ",seabirds.maxyr,"."," The mean and trend of the last five years is evaluated versus the mean and s.d. of the full time series but with the outliers removed.  Open circles indicate outliers.  The dashed lines indicate upper and lower s.d. of the full time series with outliers removed.  Blue shaded box indicates the evaluation period and the upper an lower s.d. of the full time series with the outliers included.", sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdMortalityBCCentral.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

df = load.data("Seabirds","Seabird - BeachCombers beached birds North")

DF1 = df[df$timeseries=="Brandts Cormorant(Apr - Nov) North",]
DF1$timeseries = "Brandt's Cormorant (Apr - Nov) North"

DF2 = df[df$timeseries=="Cassins auklet (Oct - Feb) North",]
DF2$timeseries = "Cassin's auklet (Oct - Feb) North"

DF3 = df[df$timeseries=="Common murre (Jun- Dec) North",]

DF4 = df[df$timeseries=="Northern fulmar (Oct - Feb) North",]
DF5 = df[df$timeseries=="Sooty shearwater (May - Oct) North",]


source('minyr.maxyr.xlim.R')

par(mfcol=c(5,1), oma=c(0,1,0,0))
te = 5

YLIM = c(0,NA) # c(0,8)

PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF1$Y2, Y.outlier = DF1$Y.outlier, AltTxt =  AltTxt, Ylab=NA) 

PlotTimeSeries(DF2, Y.lab.drop = TRUE, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF2$Y2, Y.outlier = DF2$Y.outlier, AltTxt =  AltTxt,  Ylab=NA) 

PlotTimeSeries(DF3,  Y.lab.drop = TRUE, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF3$Y2, Y.outlier = DF3$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF4$Y2, Y.outlier = DF4$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

PlotTimeSeries(DF5,  Y.lab.drop = TRUE, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF5$Y2, Y.outlier = DF5$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

mtext(side=2, "Encounter rate (dead birds/km)", cex=1, outer=TRUE)

seabirds.maxyr = maxyr
CAP = paste("Encounter rate of dead birds on NORTH XXXXXXX ",seabirds.maxyr,"."," The mean and trend of the last five years is evaluated versus the mean and s.d. of the full time series but with the outliers removed.  Open circles indicate outliers.  The dashed lines indicate upper and lower s.d. of the full time series with outliers removed.  Blue shaded box indicates the evaluation period and the upper an lower s.d. of the full time series with the outliers included.", sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdMortalityBCNorth.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

df = load.data("Seabirds","Seabird - BeachCombers beached birds Central")

DF1 = df[df$timeseries=="Brandts Cormorant(Apr - Nov) Central",]
DF1$timeseries = "Brandt's Cormorant (Apr - Nov) Central"

DF2 = df[df$timeseries=="Cassins auklet (Oct - Feb) Central",]
DF2$timeseries = "Cassin's auklet (Oct - Feb) Central"

DF3 = df[df$timeseries=="Common murre (Jun- Dec) Central",]

DF4 = df[df$timeseries=="Northern fulmar (Oct - Feb) Central",]
DF5 = df[df$timeseries=="Sooty shearwater (May - Oct) Central",]

df2 = load.data("Seabirds","Seabird - BeachCombers beached birds North")

DF6 = df2[df2$timeseries=="Brandts Cormorant(Apr - Nov) North",]
DF6$timeseries = "Brandt's Cormorant (Apr - Nov) North"

DF7 = df2[df2$timeseries=="Cassins auklet (Oct - Feb) North",]
DF7$timeseries = "Cassin's auklet (Oct - Feb) North"

DF8 = df2[df2$timeseries=="Common murre (Jun- Dec) North",]

DF9 = df2[df2$timeseries=="Northern fulmar (Oct - Feb) North",]
DF10 = df2[df2$timeseries=="Sooty shearwater (May - Oct) North",]


source('minyr.maxyr.xlim.R')

par(mfcol=c(5,2), oma=c(0,1,0,0))
te = 5

YLIM = c(0,NA) # c(0,8)



#### north

PlotTimeSeries(DF6, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF6$Y2, Y.outlier = DF6$Y.outlier, AltTxt =  AltTxt, Ylab=NA) 

PlotTimeSeries(DF7, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF7$Y2, Y.outlier = DF7$Y.outlier, AltTxt =  AltTxt, Ylab=NA) 

PlotTimeSeries(DF8, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF8$Y2, Y.outlier = DF8$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

PlotTimeSeries(DF9, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF9$Y2, Y.outlier = DF9$Y.outlier, AltTxt =  AltTxt, Ylab=NA)

PlotTimeSeries(DF10, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF10$Y2, Y.outlier = DF10$Y.outlier, AltTxt =  AltTxt, Ylab=NA)


### central
PlotTimeSeries(DF1, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF1$Y2, Y.outlier = DF1$Y.outlier, AltTxt =  AltTxt, Lmar=4, Ylab=NA) 

PlotTimeSeries(DF2, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF2$Y2, Y.outlier = DF2$Y.outlier, AltTxt =  AltTxt, Lmar=4, Ylab=NA) 

PlotTimeSeries(DF3, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF3$Y2, Y.outlier = DF3$Y.outlier, AltTxt =  AltTxt, Lmar=4, Ylab=NA)

PlotTimeSeries(DF4, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF4$Y2, Y.outlier = DF4$Y.outlier, AltTxt =  AltTxt, Lmar=4, Ylab=NA)

PlotTimeSeries(DF5, XLIM = XLIM, YLIM=YLIM, TicsEvery = te, Y2 = DF5$Y2, Y.outlier = DF5$Y.outlier, AltTxt =  AltTxt, Lmar=4, Ylab=NA)

mtext(side=2, "Encounter rate (dead birds/km)", cex=1, outer=TRUE)

seabirds.maxyr = maxyr
CAP = paste("Encounter rate of dead birds on west coast beaches through ",seabirds.maxyr,"."," The mean and trend of the last five years is evaluated versus the mean and s.d. of the full time series but with the outliers removed.  Open circles indicate outliers.  The green box indicates the upper and lower s.d. of the full time series with outliers removed.  Dotted lines indicate the evaluation period and the upper an lower s.d. of the full time series with the outliers included. Data from BeachCombers.org", sep="")

rtffile <- RTF(paste(cap.loc,"SeabirdMortality_BeachCombers.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

Appendix K: STATE-BY-STATE FISHERY LANDINGS AND REVENUES

Appendix K.1: STATE-BY-STATE LANDINGS

source("reset.DFs.R")

df = load.data("Human Activities","species_landings")
# df = df[grep("Landings", df$metric),]
df$metric = "mt x 1000"

DF1 = df[df$timeseries=="Groundfish, no hake CA",]# GFlandings
DF2 = df[df$timeseries=="Pacific hake CA",]  # hake
DF3 = df[df$timeseries=="Coastal pelagic spp, no squid CA",]  #coastalpelagics
DF4 = df[df$timeseries=="Market squid CA",]  #coastalpelagics # squid
DF5 = df[df$timeseries=="Shrimp CA",]  #shrimplandings
DF6 = df[df$timeseries=="Crab CA",]  #crablandings
DF7 = df[df$timeseries=="Salmon commercial CA",]  #salmonlandings
DF8 = df[df$timeseries=="Salmon recreational CA",]  #salmonlandings
DF8$metric = "1000's fish"
DF9 = df[df$timeseries=="Highly migratory species CA",]  #hmslandings
DF10 = df[df$timeseries=="Other species CA",]  #salmonlandings
DF11 = df[df$timeseries=="Recreational CA",]  #reclandings
DF12 =df[df$timeseries=="Total fisheries CA",]  #totallandings

source('minyr.maxyr.xlim.R')

par(mfrow=c(6,2),mar=c(0,0,0,0))
te = 10
ylim=c(0,NA)
PlotTimeSeries(DF1, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt) 
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=5) 
PlotTimeSeries(DF3, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt) 
PlotTimeSeries(DF4, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=5) 
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt) 
PlotTimeSeries(DF6, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=5) 
PlotTimeSeries(DF7, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt) 
PlotTimeSeries(DF8, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=5) 
PlotTimeSeries(DF9, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt) 
PlotTimeSeries(DF10, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=5) 
PlotTimeSeries(DF11, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt) 
PlotTimeSeries(DF12, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=5) 

CAP = paste("Annual landings of West Coast commercial (data from PacFIN) and recreational (data from RecFin) fisheries, including total landings across all fisheries from ", minyr, '-', maxyr, " in California (CA). Lines, colors, and symbols as in Fig. 1.")

rtffile <- RTF(paste(cap.loc,"CAlandings.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")
df = load.data("Human Activities","species_landings")
# df = df[grep("Landings", df$metric),]
df$metric = "mt x 1000"

DF1 = df[df$timeseries=="Groundfish, no hake OR",]# GFlandings
DF2 = df[df$timeseries=="Pacific hake OR",]  # hake
DF3 = df[df$timeseries=="Coastal pelagic spp, no squid OR",]  #coastalpelagics
DF4 = df[df$timeseries=="Market squid OR",]  #coastalpelagics # squid
DF5 = df[df$timeseries=="Shrimp OR",]  #shrimplandings
DF6 = df[df$timeseries=="Crab OR",]  #crablandings
DF7 = df[df$timeseries=="Salmon commercial OR",]  #salmonlandings
DF8 = df[df$timeseries=="Salmon recreational OR",]  #salmonlandings
DF8$metric = "1000's fish"
DF9 = df[df$timeseries=="Highly migratory species OR",]  #hmslandings
DF10 = df[df$timeseries=="Other species OR",]  #salmonlandings
DF11 = df[df$timeseries=="Recreational OR",]  #reclandings
DF12 =df[df$timeseries=="Total fisheries OR",]  #totallandings

source('minyr.maxyr.xlim.R')

par(mfrow=c(6,2),mar=c(0,0,0,0))

te=10
ylim=c(0,NA)

PlotTimeSeries(DF1, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF3, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF4, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF6, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF7, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF8, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF9, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF10, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF11, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF12, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25)  

TicsEvery=NA
CAP = paste("Annual landings of West Coast commercial (data from PacFIN) and recreational (data from RecFin) fisheries, including total landings across all fisheries from ",minyr, "-",maxyr, " in Oregon (OR). Lines, colors, and symbols as in Fig. 1.")

rtffile <- RTF(paste(cap.loc,"ORlandings.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")
df = load.data("Human Activities","species_landings")
# df = df[grep("Landings", df$metric),]
df$metric = "mt x 1000"

DF1 = df[df$timeseries=="Groundfish, no hake WA",]# GFlandings
DF2 = df[df$timeseries=="Pacific hake WA",]  # hake
DF3 = df[df$timeseries=="Coastal pelagic spp, no squid WA",]  #coastalpelagics
# DF4 = df[df$timeseries=="Market squid WA",]  #coastalpelagics # squid
DF5 = df[df$timeseries=="Shrimp WA",]  #shrimplandings
DF6 = df[df$timeseries=="Crab WA",]  #crablandings
DF7 = df[df$timeseries=="Salmon commercial WA",]  #salmonlandings
DF8 = df[df$timeseries=="Salmon recreational WA",]  #salmonlandings
DF8$metric = "1000's fish"
DF9 = df[df$timeseries=="Highly migratory species WA",]  #hmslandings
DF10 = df[df$timeseries=="Other species WA",]  #salmonlandings
DF11 = df[df$timeseries=="Recreational WA",]  #reclandings
DF12 =df[df$timeseries=="Total fisheries WA",]  #totallandings
source('minyr.maxyr.xlim.R')
te=10
par(mfrow=c(6,2))


ylim=c(0,NA)

PlotTimeSeries(DF1, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF2, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4,25) 
PlotTimeSeries(DF3, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
plot(1:10,1:10, xaxt="n", yaxt="n", pch="", bty="n", ylab=NA, bg=NULL)
PlotTimeSeries(DF5, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF6, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF7, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF8, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF9, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF10, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 
PlotTimeSeries(DF11, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Rmar=0.75) 
PlotTimeSeries(DF12, XLIM = XLIM, YLIM=ylim,   TicsEvery = te, AltTxt =  AltTxt, Lmar=4.25) 

TicsEvery=NA
CAP = paste("Annual landings of West Coast commercial (data from PacFIN) and recreational (data from RecFin) fisheries, including total landings across all fisheries from ", minyr, "-", maxyr, " in Washington (WA). Lines, colors, and symbols as in Fig. 1.")

rtffile <- RTF(paste(cap.loc,"WAlandings.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)

Appendix J.3: COMMERCIAL FISHERY REVENUES

source("reset.DFs.R")

df = load.data("Human Activities","revenue")
# df = df[grep("Revenue", df$metric),]

DF1 = df[df$timeseries == "Groundfish, no hake coastwide",] # groundfish
DF2 = df[df$timeseries == "Pacific hake coastwide",] # hake
DF3 = df[df$timeseries == "Coastal pelagic spp, no squid coastwide",] # coastalpelagics
DF4 = df[df$timeseries == "Market squid coastwide",] # squid
DF5 = df[df$timeseries == "Shrimp coastwide",] # shrimplandings
DF6 = df[df$timeseries == "Crab coastwide",] # crablandings
DF7 = df[df$timeseries == "Salmon coastwide",] # salmonlandings
DF8 = df[df$timeseries == "Highly migratory species coastwide",] # hmslandings
DF9 = df[df$timeseries == "Other species coastwide",] # reclandings
DF10 = df[df$timeseries == "Commercial fisheries coastwide",] # totallandings

source('minyr.maxyr.xlim.R')

Ylab = NA
ylim=c(0,NA)

par(mfrow=c(5,2),mar=c(0,0,0,0))
te = 10
Ylab = "Millions $"
Xaxis.cex = 0.9
PlotTimeSeries(DF1, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF2, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF3, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF4, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF5, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF6, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF7, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF8, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF9, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75, Xaxis.cex =Xaxis.cex) 
PlotTimeSeries(DF10, Ylab = Ylab,  TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25, Xaxis.cex =Xaxis.cex) 

CAP = paste("Annual revenue (Ex-vessel value in 2015 dollars) of West Coast commercial fisheries (data from PacFin) from ", minyr, "-", maxyr, ". Pacific hake revenue includes shore-side and at-sea hake revenue values from PacFIN, NORPAC (North Pacific Groundfish Observer Program) and NMFS Office of Science & Technology. ", coda, sep = "")

rtffile <- RTF(paste(cap.loc,"revenue.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

df = load.data("Human Activities","revenue")
# df = df[grep("Revenue", df$metric),]

DF1 = df[df$timeseries == "Groundfish, no hake CA",] # groundfish
DF2 = df[df$timeseries == "Pacific hake CA",] # hake
DF3 = df[df$timeseries == "Coastal pelagic spp, no squid CA",] # coastalpelagics
DF4 = df[df$timeseries == "Market squid CA",] # squid
DF5 = df[df$timeseries == "Shrimp CA",] # shrimplandings
DF6 = df[df$timeseries == "Crab CA",] # crablandings
DF7 = df[df$timeseries == "Salmon CA",] # salmonlandings
DF8 = df[df$timeseries == "Highly migratory species CA",] # hmslandings
DF9 = df[df$timeseries == "Other species CA",] # reclandings
DF10 = df[df$timeseries == "Commercial fisheries CA",] # totallandings

source('minyr.maxyr.xlim.R')

ylim=c(0, NA)
Ylab = "Millions $"
te = 10 
par(mfrow=c(5,2),mar=c(0,0,0,0))
PlotTimeSeries(DF1, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF2, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF3, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF4, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF5, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF6, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF7, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=c(0,150), AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF8, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF9, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF10, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 

Ylab=NA
TicsEvery=NA

CAP = paste("Annual revenue (Ex-vessel value in 2015 dollars) of West Coast commercial fisheries in California (CA) (data from PacFin) from ", minyr, "-", maxyr, ". Pacific hake revenue includes shore-side and at-sea hake revenue values from PacFIN, NORPAC (North Pacific Groundfish Observer Program) and NMFS Office of Science & Technology. ", coda, sep = "")

rtffile <- RTF(paste(cap.loc,"CArevenue.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")
df = load.data("Human Activities","revenue")
# df = df[grep("Revenue", df$metric),]

DF1 = df[df$timeseries == "Groundfish, no hake OR",] # groundfish
DF2 = df[df$timeseries == "Pacific hake OR",] # hake
DF3 = df[df$timeseries == "Coastal pelagic spp, no squid OR",] # coastalpelagics
DF4 = df[df$timeseries == "Market squid OR",] # squid
DF5 = df[df$timeseries == "Shrimp OR",] # shrimplandings
DF6 = df[df$timeseries == "Crab OR",] # crablandings
DF7 = df[df$timeseries == "Salmon OR",] # salmonlandings
DF8 = df[df$timeseries == "Highly migratory species OR",] # hmslandings
DF9 = df[df$timeseries == "Other species OR",] # reclandings
DF10 = df[df$timeseries == "Commercial fisheries OR",] # totallandings

source('minyr.maxyr.xlim.R')
ylim=c(0,NA)
Ylab = "Millions $"
te = 10

par(mfrow=c(5,2),mar=c(0,0,0,0))
PlotTimeSeries(DF1, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, YATS = 3, AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF2, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF3, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=c(0,15), AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF4, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF5, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, YATS = 3,AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF6, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF7, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF8, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, YATS = 2,AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF9, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=c(0,15), AltTxt = AltTxt, Rmar=0.75) 
PlotTimeSeries(DF10, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25)  

Ylab=NA
TicsEvery=NA
CAP = paste("Annual revenue (Ex-vessel value in 2015 dollars) of West Coast commercial fisheries in Oregon (OR) (data from PacFin) from ", minyr, "-", maxyr, ". Pacific hake revenue includes shore-side and at-sea hake revenue values from PacFIN, NORPAC (North Pacific Groundfish Observer Program) and NMFS Office of Science & Technology. ", coda, sep = "")

rtffile <- RTF(paste(cap.loc,"ORrevenue.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")


df = load.data("Human Activities","revenue")
# df = df[grep("Revenue", df$metric),]

DF1 = df[df$timeseries == "Groundfish, no hake WA",] # groundfish
DF2 = df[df$timeseries == "Pacific hake WA",] # hake
DF3 = df[df$timeseries == "Coastal pelagic spp, no squid WA",] # coastalpelagics
DF4 = df[df$timeseries == "Market squid WA",] # squid
DF5 = df[df$timeseries == "Shrimp WA",] # shrimplandings
DF6 = df[df$timeseries == "Crab WA",] # crablandings
DF7 = df[df$timeseries == "Salmon WA",] # salmonlandings
DF8 = df[df$timeseries == "Highly migratory species WA",] # hmslandings
DF9 = df[df$timeseries == "Other species WA",] # reclandings
DF10 = df[df$timeseries == "Commercial fisheries WA",] # totallandings

source('minyr.maxyr.xlim.R')
ylim=c(0,NA)
Ylab = "Millions $"
te=10

par(mfrow=c(5,2),mar=c(0,0,0,0))
PlotTimeSeries(DF1, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar = 0.75) 
PlotTimeSeries(DF2, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF3, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=c(0,15), AltTxt = AltTxt, Rmar = 0.75) 
plot(1:10,1:10,pch="", xaxt="n", yaxt="n", bty="n", xlab=NA, ylab=NA) 
PlotTimeSeries(DF5, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar = 0.75) 
PlotTimeSeries(DF6, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=c(0,150), AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF7, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Rmar = 0.75) 
PlotTimeSeries(DF8, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25) 
PlotTimeSeries(DF9, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, AltTxt = AltTxt, Rmar = 0.75) 
PlotTimeSeries(DF10, Ylab = Ylab,   TicsEvery=te, XLIM=XLIM, YLIM=ylim, AltTxt = AltTxt, Lmar=4.25)

CAP = paste("Annual revenue (Ex-vessel value in 2015 dollars) of West Coast commercial fisheries in Washington (WA) (data from PacFin) from ", minyr, "-", maxyr, ". Pacific hake revenue includes shore-side and at-sea hake revenue values from PacFIN, NORPAC (North Pacific Groundfish Observer Program) and NMFS Office of Science & Technology. ", coda, sep = "")

rtffile <- RTF(paste(cap.loc,"WArevenue.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)

Appendix L: FISHING GEAR CONTACT WITH SEAFLOOR HABITAT

source("reset.DFs.R")

# these are all incorrect.  Currently for coastwise.
df = load.data("Human Activities",'nonfisheries')
DF1 = df[df$timeseries=="Gear contact with seafloor habitat (weighted) Coastwide",]

df = load.data("Human Activities","nonfisheries")
DF1 = df[df$timeseries == 'Bottom trawl contact with seafloor habitat',]
source('minyr.maxyr.xlim.R')

PlotTimeSeries(DF1, TicsEvery=5, XLIM=XLIM, AltTxt = AltTxt)

CAP = paste("Weighted distance (1000s km) of fishing gear contact with the seafloor habitat across the entire CCE (top; " ,minyr, "-", maxyr,") and within each ecoregion (bottom three panels; 2002-",maxyr,"). Lines, colors and symbols as in Fig. 1a", sep="")

rtffile <- RTF(paste(cap.loc,"gearcontact.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)

Appendix M: OTHER NON-FISHERIES HUMAN ACTIVITIES INDICATORS

source("reset.DFs.R")

df = load.data("Human Activities","nonfisheries")
DF1 = df[df$timeseries=="Nutrient input",]
source('minyr.maxyr.xlim.R')

par(mfcol=c(1,1))

PlotTimeSeries(DF1, Ylab = "Normalized sum", Title = "Nutrient input", TicsEvery = 20, MinorTics=5, XLIM=XLIM, AltTxt)

Ylab=NA
TicsEvery=NA
CAP = paste("Normalized index of the sum of nitrogen and phosphorus applied as fertilizers in WA, OR and CA watersheds that drain into the CCE from ", minyr, "-", maxyr, "." , coda, sep="")


rtffile <- RTF(paste(cap.loc,"nutrients.doc",sep = ""))  
addParagraph(rtffile, CAP)
done(rtffile)
source("reset.DFs.R")

DF1 = load.data("Climate and Ocean",'ei_hci_M')

source('minyr.maxyr.xlim.R')

PlotTimeSeries(DF1, XLIM=c(1979,NA),TicsEvery = 10, Y2 = NA, MinorTics=1, PERIOD = 60, Ylab = "Habitat area", YLIM = c(0,NA), AltTxt = AltTxt)

CAP = paste0('Monthly habitat compression index (SST < 12C, x100 km^2) for ', minyr, "-", maxyr, ".", coda)

rtffile <- RTF(paste(cap.loc,"HabitatCompressionIndexMonthly.doc",sep = ""))  # this can be an .rtf or a .doc
addParagraph(rtffile, CAP)
done(rtffile)

OLD STUFF NO LONGER USED

# fig.width = 6, fig.height = 4.25
# source('reset.DFs.R')
# 
# DF = load.data("Domoic Acid", "WDOH DA Result")
# # rename stuff
# DF$timeseries = NA
# DF$timeseries[grep("Quinault",DF$SiteName)] = "Quinault"
# DF$timeseries[grep("Copalis",DF$SiteName)] = "Copalis"
# DF$timeseries[grep("Mocrocks",DF$SiteName)] = "Mocrocks"
# DF$timeseries[grep("Twin Harbors",DF$SiteName)] = "Twin Harbors"
# DF$timeseries[grep("Willapa Spits",DF$SiteName)] = "Willapa Spits"
# DF$timeseries[grep("Long Beach",DF$SiteName)] = "Long Beach"
# 
# # get monthly max
# DF$metric = "Domoic acid (ppm)"
# DF$index = as.numeric(as.character(DF$index))
# DF$Date =  DF$year
# DF$Month = substring(DF$Date,6,7)
# DF$year = paste0(substring(DF$Date,1,7),"-15")
# DFx = aggregate(index ~ year + Month + metric + timeseries + Waterbody + type , data=DF, FUN=max)
# DFx = DFx[order(DFx$year),]
# DF1 = DFx
# DF1$metric = "Monthly max (ppm)"
# 
# write.table(DF1, "Monthly_DomoicAcid_bySite.csv", col.names = TRUE, row.names = FALSE, sep=',')
# 
# source('minyr.maxyr.xlim.R')
# 
# par(mfrow=c(3,2))
# th = 20
# sites = c("Quinault", "Copalis","Mocrocks","Twin Harbors","Willapa Spits","Long Beach")
# 
# for(i in 1:6){
#   DFp = DF1[DF1$timeseries == sites[i],]
#   if(i == 3){YLAB = DF1$metric[1]}else{YLAB = NA}
#   PlotTimeSeries(DFp, Ylab = YLAB, YLIM=c(0,200), Y.lab.drop = TRUE, TicsEvery = 5, 
#                  threshold=20, threshold.loc = "above", 
#                  AltTxt = AltTxt, AltTxt.file.name = paste("Demoic Acid", sites[i]), XLIM = c(1990,2020))
#   
# }
# 
# CAP = paste("Monthly maximum domoic acid concentration (ppm) in razor clams through ", maxyr, ". The blue line is the managment threshhold of ", th," ppm.",coda, sep="")
# 
# rtffile <- RTF(paste(cap.loc,"Domoic_Acid.monthly.olddoc",sep = ""))  # this can be an .rtf or a .doc
# addParagraph(rtffile, CAP)
# done(rtffile)
# 
# source('reset.DFs.R')
# # NOTE - timeseries = Waterbody3
# 
# 
# DF0 = load.data("Domoic Acid", "DomoicAcid_All")
# DF1 = aggregate(index ~ yr.mo + species + timeseries + metric + type, data=DF0, FUN = max)
# DF1$year = as.POSIXct(as.character(DF1$yr.mo))
# source('minyr.maxyr.xlim.R')
# 
# 
# 
# par(mfrow = c(2,2), oma=c(0,0,0,0))
# 
# regions = c("WA Coast", "OR Coast",  "NCA", "CCA") # for plot order
# th=20
# 
# for(i in 1:length(regions)){
#   # subset specific data
#   DFx = DF1[DF1$species=='Razor clam' & DF1$timeseries == regions[i],]
#   # expand to include NAs for non sampled months
#   yr = minyr:maxyr
#   mo = 1:12
#   for(k in 1:length(yr)){
#     ymd = paste(yr[k],mo,15, sep = "-")
#     if(k==1){YMD = ymd}else{YMD = cbind(YMD, ymd)}
#   } # end k
#   YMD = data.frame(as.POSIXct(YMD))
#   colnames(YMD) <- 'year'
#   YMD$index = DFx$index[match(YMD$year, DFx$year)]
#   YMD$timeseries = regions[i]
#   YMD$metric = "Monthly max (ppm)"
#   YMD$type = DFx$type[1]
#   # replace blanks with zeros to make prettier plots
#   # YMD$index[is.na(YMD$index)] <- 0
#   PlotTimeSeries(YMD, XLIM = c(NA, maxyr+1), Y2 = NA, Ylab = NA, YLIM = c(0,NA), Pt.cex = 0.01, threshold = th, threshold.loc = "above", threshold.correct=TRUE, AltTxt = NA)
# 
# } # end i
# mtext(side=2, "Monthly max (ppm)", outer= TRUE, line = -1)
# 
# CAP = paste("Monthly maximum domoic acid concentration (ppm) in razor clams through ", maxyr, " for WA, OR, northern CA and central CA coast. The blue line is the managment threshhold of ", th," ppm. Dotted lines indicate missing data",coda, sep="")
# 
# rtffile <- RTF(paste(cap.loc,"Domoic_Acid_Monthly_byState.doc",sep = ""))  # this can be an .rtf or a .doc
# addParagraph(rtffile, CAP)
done(rtffile)

Gear Contact with Seafloor

# source('reset.DFs.R')
# 
# DF1 = load.data("old.data","disturbance")
# minyr = 1999 #as.numeric(substring(min(DF1$year,DF2$year,DF3$year, DF4$year,DF5$year,DF6$year,DF7$year,DF8$year,DF9$year,DF10$year,na.rm = TRUE),1,4))
# DF1$year = substring(DF1$year,1,10)
# source('minyr.maxyr.xlim.R')
# XLIM = c(1981, NA)
# 
# par(mfcol=c(1,1),mar=c(0,0,2,0))
# 
# PlotTimeSeries(DF1, Ylab =  "Landings (1000s mt)", Title =  "Bottom contact PLACEHOLDER", AltTxt =  AltTxt, XLIM = XLIM, TicsEvery = 5) 
# TicsEvery = NA
# 
# CAP = paste("Cumulative weighted distance of fishing gear contact with bottom habitat across the entire CCE,", minyr,"-",maxyr,".",coda,sep="")
# 
# rtffile <- RTF(paste(cap.loc,"disturbance.doc",sep = ""))  # this can be an .rtf or a .doc
# addParagraph(rtffile, CAP)
# done(rtffile)


marinebon/ecoidx documentation built on Jan. 19, 2022, 1:46 p.m.